【发布时间】:2013-07-13 06:49:51
【问题描述】:
我有这些模型:
class Company < ActiveRecord::Base
has_many :categorizings, as: :categorizable
has_many :categories, :through => :categorizings
class Categorizing < ActiveRecord::Base
belongs_to :category
belongs_to :categorizable, polymorphic: true
class Category < ActiveRecord::Base
has_many :categorizings
has_many :categorizables, through: :categorizings
我怎样才能获得所有具有特定类别的公司?
我试过了
Category.find_by_name("fff").companies
加上许多其他解决方案,但无法正常工作
谢谢!
【问题讨论】:
-
我只能想象语言学家看到这个会经历的痛苦...... :)
-
如果您没有公司关系,您希望它如何工作?
标签: ruby-on-rails activerecord polymorphic-associations