【问题标题】:Rails where with many to many relation具有多对多关系的 Rails
【发布时间】:2016-12-11 20:52:10
【问题描述】:
class Product < ActiveRecord::Base
    has_and_belongs_to_many :product_categories

end

class ProductCategory < ActiveRecord::Base  
    has_and_belongs_to_many :products
end

我有一个产品类别数组,我需要选择属于数组中某个类别的所有产品

谢谢,Rotem

【问题讨论】:

  • 这样的? product_categories.each { |pr| pr.products }

标签: ruby-on-rails ruby-on-rails-4 where


【解决方案1】:

示例:

ProductCategory.first.products

将列出属于第一个产品类别的所有产品。

【讨论】:

    猜你喜欢
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多