Hello,
I am using Sqlite DB, with Elixir and Sqlalchemy on top of it. For an
ondelete="cascade" on Many to one relationship, the SQL generated in
the background doesn't seem to be right.
I am aware that Sqlite just parses FK constraint statements, but does
not support it. In my model, I have a Movie and Director objects.
There is a many to one relationship from Movie to Director.
>>> d
<Director S Speilberg>
>>> d.movies
[<Movie "Titanic", (1999) by <Director S Speilberg>>, <Movie "Catch me
if you c
n!", (1998) by <Director S Speilberg>>]
>>> session.delete(d)
>>> session.flush()
2008-07-29 11:11:31,148 INFO sqlalchemy.engine.base.Engine.0x..d0
BEGIN
2008-07-29 11:11:31,180 INFO sqlalchemy.engine.base.Engine.0x..d0
UPDATE movie S
ET director_id=? WHERE movie.title = ? AND movie.year = ?
2008-07-29 11:11:31,226 INFO sqlalchemy.engine.base.Engine.0x..d0
[None, 'Catch
me if you can!', 1998]
2008-07-29 11:11:31,289 INFO sqlalchemy.engine.base.Engine.0x..d0
UPDATE movie S
ET director_id=? WHERE movie.title = ? AND movie.year = ?
2008-07-29 11:11:31,335 INFO sqlalchemy.engine.base.Engine.0x..d0
[None, 'Titani
c', 1999]
2008-07-29 11:11:31,367 INFO sqlalchemy.engine.base.Engine.0x..d0
DELETE FROM di
rector WHERE
director.id = ?
2008-07-29 11:11:31,414 INFO sqlalchemy.engine.base.Engine.0x..d0 [1]
2008-07-29 11:11:31,428 INFO sqlalchemy.engine.base.Engine.0x..d0
COMMIT
After deleting the director, SQL is issued on all Child Movie objects
to UPDATE the Foreign Key (Director's ID) to None.
Shouldn't it be DELETE FROM MOVIE WHERE director_id=? [<director
id>] ?
Is there a way to get this kind of SQL to be issued?