David Raffauf
2010-Nov-07 20:06 UTC
Nested Forms and HABTM fails for existing model, no join record
I am trying to created a nested form with a HABTM association and I am
unable to find an approach that works for all cases.
What I am trying to achieve is a Project form that can:
1. Create a new project and create new company to associate with it
- This works perfectly
2. Create a new project with an existing company via autocomplete.
- This fails because it''s looking for an existing record in the HABTM
join table *before* there is a project id.
Here is the SQL that comes out of this failed case:
SELECT "companies".* FROM "companies" INNER JOIN
"companies_projects" ON
"companies".id = "companies_projects".company_id WHERE
("companies"."id"
IN (''6'')) AND ("companies_projects".project_id =
NULL )
In my Project model I am using:
accepts_nested_attributes_for :companies
Is this the wrong approach to tackling this use case? I''ve read that
this is only good for 1-1 or 1-n relationships. What is the preferred
method for doing something like this?
Thanks in advance,
David
--
Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.