Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL-Rails深度嵌套联接_Sql_Ruby On Rails_Join_Tags_Include - Fatal编程技术网

SQL-Rails深度嵌套联接

SQL-Rails深度嵌套联接,sql,ruby-on-rails,join,tags,include,Sql,Ruby On Rails,Join,Tags,Include,首先,我是法国人,很抱歉我的英语不好 我有以下型号: 购物 has_and_belongs_to_many :products 产品 has_and_belongs_to_many :shops has_many :taggings has_many :tags, through: :taggings 标记 belongs_to :tag belongs_to :product has_many :taggings has_many :products, through: :tagging

首先,我是法国人,很抱歉我的英语不好

我有以下型号:

购物

has_and_belongs_to_many :products
产品

has_and_belongs_to_many :shops
has_many :taggings
has_many :tags, through: :taggings
标记

belongs_to :tag
belongs_to :product
has_many :taggings
has_many :products, through: :taggings
标记

belongs_to :tag
belongs_to :product
has_many :taggings
has_many :products, through: :taggings

我希望能够进行
购物。首先.tags
,因此如果可能的话,我希望在一次请求中获得所有商店产品的标签。如果我可以解释一下,那就好了:)

您没有在
商店
模型上指定
标签
的关系。为了在单个对象上调用
#标记
,需要添加该关系

class Shop
  # ...
  has_many :tags, :through => :products
  # ...
end

那太简单了。。。我试着做一些类似Shop.joins(products:[taggings::tags])。。。谢谢你,这很有效!