On Apr 18, 1:33 pm, Joel VanderWerf <[email protected]> wrote: > On 04/18/2011 01:24 PM, Jeremy Evans wrote: > > I think this is a simpler way to do things: > > > baz = Baz.create > > bar = Bar.create(:baz=>baz) > > foo = Foo.create(:bar=>bar) > > baz.update(:foo=>foo) > > Thanks, that confirms that this sequence of four steps is essential.
Yes. Intuitively, this makes sense, as an SQL database requires 4 separate queries to do so (3 inserts + 1 update). It is possible to have a library take an arbitrary unsaved (or partially saved) object graph with cyclic dependencies and handle things correctly in the cases where it is possible to do so. My fixtures library, fixture_dependencies, is one such library, and uses the same idea as your code (deferred procs). Due to the inherent complexity and fairly rare need, I don't think it's something Sequel should attempt to handle by default. Sequel actually doesn't handle any deferred saving in associations by default (this is why the add_* association methods on an unsaved object raises an error), though the nested_attributes plugin implements such functionality (again by deferring procs). Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
