Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

Doctrine / Symfony model won't delete when instanciated with new

A quick question, but does anyone know why the code below won't actually delete anything from my database? The ->delete() returns true...

$model = new Model();
$model->setPrimaryKeyPart1($value1);
$model->setPrimaryKeyPart2($value2);
$model->delete(); // returns true, but isn't deleted.

Note that this model is a many to many table with all values being the primary key.

I have the feeling it has something to do with it having a isNew flag, is there any way to delete the model this way without having to query it from the database?

Upvotes: 0

Views: 97

Answers (1)

j_freyre
j_freyre

Reputation: 4738

Your object $model don't come from the database but is programmatically initialized.

Even if you set PK1 and PK2. There is no database connection associated with the object.

It should be better to retrieve the object from the db and then delete it.

Upvotes: 3

Related Questions