spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

CRUDelete (? #255

Closed luchothoma closed 6 years ago

luchothoma commented 6 years ago

I am new with Spot and in the doc http://phpdatamapper.com/docs/crud/ It does not say how to Delete an entity.... I try with ->delete( $primariKeyValue ) but it not works.

luchothoma commented 6 years ago

I solve it, it need the $ObjectToDelete, not the $id, althoug it will be useful update/add it to documentation.

FlipEverything commented 6 years ago

Unfortunately there are a lot of undocumented features in spot. I wanted to upgrade the documentation so many times in the past months.......

You can do it both ways:

$mapper->delete($entity);

or

$mapper->delete([$primaryKeyField => $entity->$primaryKeyField]);
Arzaroth commented 6 years ago

Shouldn't your second line be :

$mapper->delete([$mapper->primaryKeyField() => $entity->primaryKey()]);

? That being said, if you pass an object (so an entity most of the time) to $mapper->delete, that's almost what's being done internally by spot (as seen here), so you shouldn't have to do it manually most of the time.

FlipEverything commented 6 years ago

I was writing an example from the top of my head, and I implicitly set the $primaryKeyField variable. Ofc you can delete an entity if you pass it to $mapper->delete, but you can delete entities if you provide a fitting $options array as well.

FlipEverything commented 6 years ago

Feel free to reopen this thread if you need further assistance.