set other relations to null on delete when dbms does not do it #7

Closed
cebe opened this Issue Mar 13, 2012 · 10 comments

2 participants

@cebe
yiiext member

similar to #6

@cebe
yiiext member

also delete MANY_MANY relations before delete()

@cebe
yiiext member

will not support this. DBMS should defiine foreign key behavior.

@cebe cebe closed this Jun 13, 2013
@schmunk42

Hi cebe, just stumbled upon this :)
How to handle SQLite then? Maybe you can define the constraints (eg. DELETE CASCADE) in the behavior.
Would love to hear your thoughts about this.

@cebe
yiiext member
@schmunk42

Hmm, sorry, it seems I am getting old 👴 ... http://www.sqlite.org/releaselog/3_6_19.html

Thank you!

@schmunk42

And I also mixed it up with: http://www.yiiframework.com/doc/api/1.1/CSqliteSchema/#addForeignKey-detail
I'd have some use-cases, where I want to add FK to existing tables, also if they are SQLite.

Any ideas how to work around this limitation, besides overriding this method with some code which creates a new table with FKs and copies all records?

@cebe
yiiext member

Yeah, guess you should update then ;)

@cebe
yiiext member

You can define foreign key directly in table definition:

$this->createTable('...', array(
    'col1' => 'type',
    // ...
    'FOREIGN KEY (col1) REFERENCES othertable(id) ON DELETE ... ON UPDATE ...'
))
@schmunk42

Sure, I meant for adding FKs later to a SQLite table.
You'd have to setup a temporary table with the correct createTable statement including ON DELETE.
Then copy all values to the temp table, remove the originial one and then rename the temp table.

@cebe
yiiext member

Can't see a better way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment