Joining a one-to-many association with a many-to-many association in Rails 3
Posted
by Maz
on Stack Overflow
See other posts from Stack Overflow
or by Maz
Published on 2010-06-17T16:48:06Z
Indexed on
2010/06/17
16:53 UTC
Read the original article
Hit count: 277
Hi all,
I have a many-to-many association between a User class and a Table class. Additionally, i have a one-to-many association between the User and the Table (one User ultimately owns the table). I am trying to access all of the tables which the user may access (essintally joining both associations).
Additionally, it would be nice to do this this with named_scope (now scope)
Here's what I have so far:
class User < ActiveRecord::Base
acts_as_authentic
attr_accessible :email, :password, :password_confirmation
has_many :feedbacks
has_many :tables
has_many :user_table_permissions
has_many :editableTables, :class_name => "Table", :through => :user_table_permissions
def allTables
editableTables.merge(tables)
end
end
Thanks.
© Stack Overflow or respective owner