I know that the general order in which models are saved is the deepest child first, and then gradually up to the parent. But I'm wondering with respect to other callbacks, does it happen something along the lines of:
ChildA - before validation
ChildB - before validation
Parent - before validation
ChildA - after validation
ChildB - after validation
Parent - after validation
ChildA - before save
ChildB - before save
Parent - before save
...
OR along the lines of:
ChildA - before validation
ChildA - after validation
ChildA - before save
...
ChildB - before validation
ChildB - after validation
ChildB - before save
...
Parent - before validation
Parent - after validation
Parent - before save
...
The reason this is important is that I have callbacks that adjust attributes, and the adjustability of an attribute on a model depends on the attributes of other models.
One example is that I want the Parent
to auto-set its status
attribute to be Complete
if ChildA
and child B's
statusattributes are both
Completeand the children are both
valid`.
I tried to test this using puts
statements, but apparently, that leads to some weird behaviour (see this question: Nested form validation statements repeating multiple times), and I'm afraid it's not representative.
I definitely read the Rails Guides, but maybe I'm blind because I didn't see a reference to this anywhere...