【发布时间】:2010-08-08 08:37:30
【问题描述】:
我有三个模型(这里简化):
class Child < ActiveRecord::Base
has_many :childviews, :dependent => :nullify
has_many :observations, :through => :childviews
end
class Childview < ActiveRecord::Base
belongs_to :observation
belongs_to :child
end
class Observation < ActiveRecord::Base
has_many :childviews, :dependent => :nullify
has_many :children, :through => :childviews
end
我正在使用 Rails 的 to_json 方法将其发送到一些 JavaScript,如下所示:
render :layout => false , :json => @child.to_json(
:include => {
:observations => {
:include => :photos,
:methods => [:key, :title, :subtitle]
}
},
:except => [:password]
)
这非常有效。观察结果可以“通过”连接表(子视图)很好地检索。
然而,我还想获取位于 childviews 连接表中的数据;特别是“needs_edit”的值。
我不知道如何在 to_json 调用中获取这些数据。
谁能帮帮我?非常感谢。
qryss
【问题讨论】:
标签: ruby-on-rails json has-many-through model-associations