Dave Krupinski
2006-Jan-09 03:04 UTC
[Rails] Newbie Question. I''m dumb with forms and foreign keys
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 -- Posted via http://www.ruby-forum.com/.
Pat Maddox
2006-Jan-09 03:54 UTC
[Rails] Newbie Question. I''m dumb with forms and foreign keys
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 On 1/8/06, Dave Krupinski <rails@tarantulapictures.com> wrote:> 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >