我设置了has_many:通过与连接模型上的位置列关联,这样我就可以保存演习列表。但是现在我正在寻找与控制器中的这些对象进行交互的最佳方式。使用has_many创建一个有序列表:通过
我应该打电话Activity.drills
或Activity.drill_list
获得有序列表吗?
维持职位的最佳方式是什么?我是否必须手动更新DrillList中的所有位置?
class Drill < ActiveRecord::Base
has_many :drill_list, :order => "position"
has_many :activities, :through => :drill_list, :order => "position"
end
class DrillList < ActiveRecord::Base
belongs_to :activity
belongs_to :drill
end
class Activity < ActiveRecord::Base
has_many :drill_list, :order => "position", :dependent => :destroy
has_many :drills, :through => :drill_list, :order => "position"
end
有人可以解释我在这里发生了什么? – fl00r 2011-04-22 19:28:30