Hi Adam,
The parent already exists. I''m create the child, then update some of
its fields with the params returned from a form. I''ve included some
of the code below (shistory_item''s ''emrec_id'' field
is declared ''not null'') The app''s crashing on the
''update_params'' call. I''m wondering if I can just
add a parameter in the private method call, or if I have to change its logic to
add a specific assignment of the emrec_id.
Thanks in advance for any help!
Bill
--------------------------------------------------------------------
# relevant code from the ''update'' method in
shistory_controller.rb
...
@emrec = find_emrec
@shistory_item = find_shistory
@shistory_item.update_attributes(params[:shistory_item])
...
# and then, below...
private
def find_shistory
session[:shistory] ||= ShistoryItem.new
end
----- Original Message -----
From: Adam Denenberg
To: rails@lists.rubyonrails.org
Sent: 2006-03-11 12:15 PM
Subject: Re: [Rails] assignment of parent ID in child''s fk field
well if you create the child data first, you then need to associate it to a
parent. For example if you have a page with many words
Then i *think* you can do something along the lines of
page = Page.new
page.words << Words.new(@params[:word])
page.save
I might be a little off here but I think thats the idea. If you post some
code then maybe we can understand what you are doing wrong.
adam
On 3/11/06, Bill Walton <bill.walton@charter.net> wrote:
When I create a child record I''m not automagically getting the
parent ID put into the fk field. Does object.new take parameters that allows me
to do that as part of the AR record creation? Or do I need to do it separately?
Or am I missing the boat altogether ;-)
Thanks,
Bill
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
------------------------------------------------------------------------------
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/5172b63b/attachment.html