On Jul 30, 2012, at 7:23 PM, kris wrote: > > So > 3. Is there a fool-proof way to configure your table and mapper such that > you will get the most efficient delete strategy? > ON DELETE CASCADE when available or SA when not?
unfortunately this is not something built in to SQLAlchemy at this time. So you'd need to make it some kind of configuration option in your application, that would need to be established before you create your mappings - then you'd pass that flag along to all your "passive_deletes" flags. What we're not getting here is the ability to automatically determine the "passive_deletes" flag *after* the engine has been connected. It's probably not too hard to get the RelationshipProperty to respond to a change in the "passive_deletes" flag, it's just not something that's been tested (meaning, maybe you could say, MyObject.somerelationship.passive_deletes = True after the fact). In any case I don't know that SQLAlchemy would want to determine this flag automatically in any case as we're basically talking about a per-table quality with MySQL (MyISAM vs. InnoDB) and a pragma setting with SQLite, but at least if passive_deletes accepted some kind of callable that is passed the dialect or something would make "automatic" behavior here possible. But it gets even more weird if you were using a Session connected to multiple databases, some supporting on delete cascade and others not. > > 4. Can I always add ondelete='cascade' and it will be ignored (or filtered) > if the underying DB doesn't support it. mmm in the case of SQLite and MySQL this should work fine. I think every other DB we support has support for ON DELETE CASCADE. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en.
