This gist shows the whole issue we're having: 
https://gist.github.com/benalavi/35429576f87c1bd675e81bc19fb80174

It looks like when you create an object along w/ multiple related objects 
via nested attributes through a one_to_many association validations are run 
multiple times (which may be on purpose?) and the reciprocal association 
cache on the to_many side is cleared before the 2nd validation (and before 
any _save hooks).

So if you reference the reciprocally associated object in a validation or 
save hook it is then queried again for every associated object being saved, 
which in our case ended up leading to a substantial performance issue 
because we assumed the reciprocal association was preserved.

Is this a bug? If so I can dig deeper and work on a patch (of course any 
advice would be great :))

Or is there maybe an option somewhere to change this behavior? Or is this 
simply expected behavior for nested attributes? (it doesn't seem to happen 
when using adder methods).

The output from that gist I get is (showing the object_id of the reciprocal 
object):

Creation w/ nested_attributes
Track validate 70306570765160
Track validate 
Track before_save 

Creation using adder w/ given reciprocal reference
Release id: 70306570435020
Track validate 70306570435020
Track before_save 70306570435020

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to