rails active_hash包含/ join?

时间:2015-12-02 16:11:57

标签: ruby-on-rails activerecord

我使用的是active_hash gem,我不确定是否支持加入/包含,或者我做错了什么......

我的模型是:学校(ActiveRecord)belongs_to Commune(ActiveHash)和地区(ActiveHash)has_many communes

School.includes(:commune) 
NoMethodError: undefined method `type_for_attribute' for Commune:Class

School.joins(:commune)
NoMethodError: undefined method `table_name' for Commune:Class

模特:

公社

class Commune < ActiveHash::Base
    include ActiveHash::Associations
    belongs_to :region    
    has_many :schools
end

学校

class School < ActiveRecord::Base
    include ActiveHash::Associations
    attr_accessor :region
    extend ActiveHash::Associations::ActiveRecordExtensions
    belongs_to :commune
end

区域

class Region < ActiveHash::Base
    include ActiveHash::Associations
    has_many :communes
end

我读过的文档:https://github.com/zilkey/active_hash#referencing-activehash-objects-from-activerecord-associations

School.last.commune.nameSchool.last.comune.region.name等所有操作都可以正常运行

问候!

0 个答案:

没有答案