has_and_belongs_to_many 関係を持つタスクとリストを取得したとします。
class Task < ActiveRecord::Base
attr_accessible :content, :due_date
has_and_belongs_to_many :lists
end
class List < ActiveRecord::Base
attr_accessible :title, :user_id, :space_free_title
has_and_belongs_to_many :tasks
end
また、タスクは多くのリストにある可能性があるため、関連するモデル/テーブルを取得しました:
class ListsTasks < ActiveRecord::Base
attr_accessible :list_id, :task_id
end
これで、list_id ですべての ListsTasks を取得する方法がわかりました。
ListsTasks.find_all_by_list_id(1)
しかし、ListsTasks に基づいてタスクの内容を取得するにはどうすればよいでしょうか?