Reputation: 623
I have the following models:
User, ProcessType and Remark, as follows:
class User < ActiveRecord::Base
has_many :process_type
end
class Remark < ActiveRecord::Base
belongs_to :process_type
end
class ProcessType < ActiveRecord::Base
belongs_to :user
has_many :remarks
end
only some Users are associated with a ProcessType. When a Remark is added, it gets associated with a certain ProcessType (and each ProcessType has a User responsible). I want that when the User associated with a certain ProcessType logs in, to see all Remarks of that processType.
I am not able to figure out the correct approach, maybe someone could help me.
Thanks!
Upvotes: 0
Views: 44
Reputation: 17834
in User.rb, you can have association with remarks directly since user is associated with process_type and process_type is associated with remarks
has_many :remarks, :through => :process_type
Then to see all remarks you can write this ActiveRecord query
current_user.remarks
Upvotes: 1