在
Ruby on Rails中,我有一个有很多孩子的学校.儿童有很多活动.和Activity有一个activity_types.我需要帮助嵌套包括.在我的儿童控制器.我有这个……哪个有效.
s = School.find(params[:school_id]) @school = s @children = s.children.includes(:activities).all
但我想从孩子们的活动中获取:activity_type.我试过这个
s = School.find(params[:school_id]) @school = s @children = s.children.includes(:activities => :activity_types).all
但那没用
解决方法
不要复活activity_type.
s.children.includes(:activities =>:activity_type).all