ドリルのリストを保存できるように、結合モデルの位置列との関連付けをhas_many:throughに設定しました。しかし、今私は、コントローラ内のこれらのオブジェクトと対話する最善の方法を探しています。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