Given the following relations (see bottom of post) n:m Users - Tabs (has_many has_many; trough sharedtabs) 1:n Tabs - Tasks (has_many and belongs_to)
I am stuck in the queries: @test = User.find(2).tabs.find(3).tasks ← all tasks in tab #3 of user 2, works
I want to query all tasks that belong to all tabs of a particular user @test = User.find(2).tabs.tasks ← undefined method tasks @test = User.find(2).tabs.find(:all).tasks ← undefined method tasks
I most likely will bang my head against the wall seeing the solution, still, I read doc after doc without a solution except stepping through each of the user tabs one after the other
class User < ActiveRecord::Base
Include default devise modules. Others available are:
:token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :sharedtabs, :dependent => :destroy has_many :tabs, :through => :sharedtabs, :dependent => :destroy end
class Tab < ActiveRecord::Base has_many :tasks, :dependent => :destroy
has_many :sharedtabs, :dependent => :destroy has_many :users, :through => :sharedtabs end
class Sharedtab < ActiveRecord::Base
belongs_to :user
belongs_to :tab
end
class Task < ActiveRecord::Base belongs_to :tab end