Forum: Ruby on Rails Newbie Question. I'm dumb with forms and foreign keys

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5919c62ada270c8ffff2b5c7d46a840c?d=identicon&s=25 Dave Krupinski (davis)
on 2006-01-09 04:04
For some reason I am just not able to get this.

I am trying to setup an organizational hierarchy, so I have a
organization which works fine.  From there I want to be able to define
new divisions, departments, areas, etc.

For creating a Division, my original thought was to pass the
organization's id to the new organization unit form, and then do a
Division.new(:organization_id => params[:id]) but of course that fails
because it looks like doing a Object.new ignores any id or foreign keys
in the object.

I am assuming (and hoping) there is a simple solution or convention on
how to accomplish this and I'm just completely missing it.

Thanks,
Dave
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-09 04:56
(Received via mailing list)
d = Division.new(params)
d.organization_id = params[:id]


One question I have for others, is there any reason or advantage to
use objects instead of purely the fkey?  i.e.
d.organization = Organization.find(params[:id])

One simple reason is that you have fewer database issues.  If you were
to change the fkey name, you simply need to update it in the model.
That's unlikely though, and I was wondering if there are any practical
reasons why you might want to access it via association, which has the
overhead of pulling the record from the db.

Pat
This topic is locked and can not be replied to.