Max M. wrote:
On 12/14/06, Steve M. [email protected] wrote:
I’ve been trying to fill in some of the gaps as I run into them,
this issue?
Seems like an important tool: to be able to not just navigate but create
relationships between two related tables. I can see the pain point: how
to allow additional model data into the join table, if it requires it
for referential or data integrity…
Any news on this thread would be appreciated.
Steve
Adding to has_many :through via << works for me in Edge rails. There
is a problem with self-referential relationships, for which I have
filed a patch:
http://dev.rubyonrails.org/ticket/6744
Have a look if that helps you.
Cheers,
Max
Hi Max,
Thanks for this reference - I had noticed your posting about
self-references while researching this problem, though I wasn’t certain
it was related.
(I am using 1.1.6 Rails) Just to be clear, when you say that adding two
models using “has_many :through” works for you, does this mean that you
are able to add both models and the model that connects them is
correctly updated to include a join record as well?
So, assume tables with pseudo-Rails code like:
owner
id
name :string
property
id
location : string
owner_property (join table)
id
owner_id
property_id
created_at [etc → i.e. other 5th normal columns)
Property
has_many :owner_property
has_many :owner, :through => owner_property
Owner
has_many :owner_property
has_many :property, :through => owner_property
OwnerProperty
has_many :owner
has_many :property
Can you execute this code or equivalent with the appropriate results
(detailed below)
owner.create!({:name => “User 1”})
property.create!({:location => “101 Main St”})
owner << property
owner.save!
property.save! # not sure if either save! statement is even necessary
If working correctly this would yields a new owner record (say id:15), a
new property record (say id:20) and a new owner_property record with
owner_id = 15 and property_id = 20 (and created_at => [Now])…
I’ll be very curious if this is working well for some people because I’m
totally flummoxed on getting it to work in my setup.
Thanks for any input or suggestions. I’m happy to move up to Edge rails
if it’s necessary but I prefer to work on the stable release because
that’s what I’ll be (soon) deploying under (am I foolish to do this?)
Sincerely,
Steve