2013-07-13 54 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

你怎么指望,如果你这个工作没有公司关系? –

回答