Let’s say I got tasks and lists with an has_and_belongs_to_many relationship:
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
Also I got the related model/table since a task can be on many lists:
class ListsTasks < ActiveRecord::Base
attr_accessible :list_id, :task_id
end
Now I know how to get all ListsTasks by the list_id:
ListsTasks.find_all_by_list_id(1)
But how do I get the contents of a task based on ListsTasks?
Your
ListsTasksmodel is unnecessary and is not being used by the two associations in yourListandTaskmodels.Are you looking for something like
List.find(1).tasksto get the tasks on that list?