Displaying 2 results from an estimated 2 matches for "groupable".
2006 Jul 26
3
Polymorphic Association with Single Table Inheritance?
Hello,
is it possible to setup a model/table schema like this:
Groupable --> Membership <-- Group
^ ^
| |
User UserGroup
I tried the following but failed:
Groupable (table with ''type'' column)
has_many :memberships, :as => :groupable
has_many :groups, :throu...
2006 Aug 16
0
Polymorphic Associations and grouping users and projects
...meone who is much brighter than me, is the code below the best way
to achieve this?
class User < ActiveRecord::Base
has_many :memberships, :as => :groupabale
has_many :groups, :through => :memberships
end
class Project < ActiveRecord::Base
has_many :memberships, :as => :groupable
has_many :groups, :through => :memberships
end
class Membership < ActiveRecord::Base
belongs_to :group
belongs_to :groupable, :poymorphic => true
end
class Group < ActiveRecord::Base
has_many :memberships
end
Thanks for your input!
--
Posted via http://www.ruby-forum...