I'm thinking that the following code is a step in the right
direction...
------------------------------------------------------------
 def secondary_tables
    secondary_tables_1 + secondary_tables_2
  end
--------------------------------------------------------------

....but it ruins the association links and instead prints:

---------------------------------------------------------------

#<SecondaryTable:0x2a9942de98>#<SecondaryTable:0x2a9942bdc8>

----------------------------------------------------------------

Even if there is a more elegant solution than this method of just
concatenating the two separate has_many association variables
together, it'd be nice to know how to turn these codes back into
links.

Ideas?


On Dec 12, 11:53 am, dschruth <[email protected]> wrote:
> Hello,
>
> I'm experimenting with a two to many model asssociation...   where I
> have one or two "Primaries" for each "Secondary"  and many
> "secondaries" per "primary".
>
> the following code works fine:
> ----------------------------------------------------------------------------------
> 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 would like my primary controller to only have one column linking
> to my child secondaries instead of the two ( _1 and _2).   I tried
> 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 B ends up being the only one that is linked in my one "Secondary
> Tables" column.
>
> Does anybody know how to combine these two in to one column?  Do i
> need to write a helper function for this?
>
> Thanks,
>
> Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to