Another solution could be to inverse the order: - first delete the parent (so the rule RESTRICT is immediately fired) - second set null the FKs.
On 8 sep, 19:52, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Sep 8, 2007, at 12:54 PM, Jean-Philippe Dutreve wrote: > > > > > My need is related to Postgresql ON DELETE RESTRICT/NO ACTION : I'd > > want a sql exception as soon as a parent having any existing child is > > deleted. I don't want cascade delete on children, just the parent but > > only if it has no child. > > > I've remarked that SA (0.4) first SET NULL all FKs in child table, and > > second delete the parent. Doing this in that order, the PG rule is not > > called and the parent is deleted even if there are children (now > > orphaned)!!! > > > The only solution I have found is to define the FK as NOT NULL. > > It would be handy to be able to let this PG rule be fired. > > Perhaps with an option cascade=delete-donothing on the child relation. > > the ORM is hardwired to a referential integrity model right now that > assumes foreign keys are to be maintained as valid. therefore as > long as theres a relation() present, its going to want to either null > out the foreign key or to delete the child items. There are some > options that can affect this, such as viewonly=True gives you a > relation that is only for loading, and passive-deletes=True will give > you a relation that doesnt load in unloaded objects in order to > update foreign keys (relying instaed upon ON DELETE CASCADE), but > still acts upon objects already loaded. you could just use > viewonly=True but that means you have to populate foreign key > attributes manually. > > we can look into adding an option to not act on FKS at all during a > delete operation but it might be a little involved. (adding trac > tickets would be the route for this) --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---