> I''d like to associate two model objects such as
>
> class Pair < ActiveRecord::Base
> has_one :good_member, :class_name=>''Member''
> has_one :bad_member, :class_name=>''Member''
> end
>
> class Member < ActiveRecord::Base
> belongs_to :pair
> end
>
> so that a pair has two members where one is good and the other is bad.
>
> As far as I understand, the association information would be kept in
> the "member" database table as a foreign key to the associated
"pair"
> record, e.g. member_id
>
> Since the association information is not kept within the "pair"
table
> - where it would be possible to distinguish between the good and the
> bad member, how can I do the above association?
#
# sql table has columns:
# memberable_type, :string
# memberagble_id, :integer
#
class Member < ActiveRecord::Base
belongs_to :memberable, :polymorphic => true
end
class GoodMember < Member
end
class BadMember < Member
end
class Pair < ActiveRecord::Base
has_one :good_member, :as => :memberable
has_one :bad_member, :as => :memberable
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---