2013-07-13 55 views
0

我有這些模型:軌多態性許多-to-many關聯

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 

加了很多其他的解決方案,但無法得到它的工作

THX!

+0

我只能想象的痛苦語言學家會經過看到這... :) – sscirrus

+0

你怎麼指望,如果你這個工作沒有公司關係? –

回答