dschruth wrote:> I''m working on a two-to-many relationship that works fine from the
> child object''s perspective but not from the parent''s.   
The
> imperfect, yet functional code looks like this:
> -------------------------------------------------------------------
> class PrimaryTable < ActiveRecord::Base
>   has_many :secondary_tables_1 ,
>             :foreign_key => :A_primary_table_id,
>            :class_name => "SecondaryTable"
>  has_many :secondary_tables_2 ,
>            :foreign_key => :B_primary_table_id,
>            :class_name => "SecondaryTable"
> end
> 
> class SecondaryTable < ActiveRecord::Base
>   belongs_to :A_primary_table,
>            :foreign_key => :A_primary_table_id,
>            :class_name => "PrimaryTable"
>   belongs_to :B_primary_table,
>            :foreign_key=> :B_primary_table_id,
>             :class_name => "PrimaryTable"
> end
>
------------------------------------------------------------------------------------------
> 
> But, I don''t want to have two linking fields up *and* two linking
> fields down.  I only want one linking field down.  I would like to
> lump these parent to child relationships into one associated link...
> doing something like this:
> 
>
------------------------------------------------------------------------------------------
> 
> class PrimaryTable < ActiveRecord::Base
>   has_many :secondary_tables ,
>            :foreign_key => :A_primary_table_id,
>            :foreign_key => :B_primary_table_id,
>            :class_name => "SecondaryTable"
> end
> 
> -------------------------------------------------
> 
> ...but only one of the two links (the ones to "B_primary_table")
shows
> up this way.
Using the :finder_sql option to has_many, you''ll have to write
custom SQL that does an "or" on the two foreign keys.
-- 
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---