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])。。。谢谢你,这很有效!