On Jul 22, 2011, at 4:16 PM, Glenn Little wrote:

> How does one enforce that any child record saved has a parent?  I've got this:

Review the ActiveRecord callbacks. Look at the order.

You need to tell the child what its parent is. You can trigger when this 
happens using the callbacks.

Write a before_validation method which ensures the parent_id has a value (which 
is likely going to be something you pass to the child in the .new / .initialize 
method).

At least, that's how I do it, but maybe there's supposed to be a better way.

-- gw


-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to