On Jul 25, 2009, at 5:19 AM, Alessandro Dentella wrote:
> > > In faq 5.13 it's explained why setting bar.foo_id would not generate > the > object bar.foo. > > I stumble in the same problem when creating a Movie in an example with > Director/Movie and a relation -'movies' on director- that has > 'delete-orphan'. > > running:: > > f = m.Movie(title="my title") > f.director_id = 1 > sess.commit() > > Would issue an error: > > Instance <Movie at 0xb7dab72c> is an unsaved, pending instance and > is an > orphan (is not attached to any parent 'Director' instance via that > classes' > 'movies' attribute) > > the reason is explained in the faq, no Director instance has been > created. The problem is that I can't use the proposed solution of > expiring > the session since the object is not yet persisted (Instance '<Movie at > 0xb7d8564c>' is not persistent within this Session). > > Wouldn't be this a situation when an automatic loading would be > possible? or > at least would it be possible to trap the error as the error really > only > should enforce that no orpahn is left, but the foreign key (if > existent) > ensures that already. the "orphan" rule right now is simple, like everything else within the ORM, the values of foreign key attributes aren't considered - they represent the "input/output" of internal ORM state, where those inputs/ outputs are things that are highly customizable, and the core can't make assumptions about them. on the inside, it only considers that Movie is attached to a Director or not. like the FAQ says, we choose not to get into generating "events" from foreign keys being set. which is not a "forever" rule, but if you look in trac there are about 300 ORM issues open that I'd rather get resolved before I have the time to consider the ramifications of a change like that. the delete-orphan thing is a convenience feature that introduces limitations such as these. If you don't use it, you have to delete orphans manually, but as long as you're using proper constraints there's no danger of the orphan "hanging around" - the constraints would not allow it. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---