Problems With Deletion

I am trying to do something similar to the results of this post (http://forum.phalconphp.com/discussion/183/insert-and-delete-multiple-related-records), but I am having troubles making this work, as well as just getting deletion to work normally.

```foreach($deletable as $single) { $user = UserProjects::findFirst(array( 'conditions' => 'userid=?0 and projectid=?1 and is_stakeholder=1', 'bind' => array( $single, $project->id ) ));

var_dump($user->delete());
exit;

```

This throws me a PDOException. I ran some code to show me the queries being generated, and for some reason I am getting: DELETE FROM users_projects WHERE. There is nothing getting appended to the end of the query.

I have ensured that I am getting a result from the initial findFirst, but, after that, nothing happens. Any ideas? I'm on Phalcon 0.9.1.



84.5k

Does UserProjects have a primary key?



3.0k

It does not. It is a pivot table. Sorry. Forgot to mention that.



84.5k

Since the SQL is dinamically generated, the ORM cannot delete a record if a primary key is not available.



3.0k

So, I take there is no way to delete from pivot tables, aside from creating the query yourself? If that's the case, that's fine.



84.5k

You can do something like:

$user->getConnection->delete("user_projects", "user_id=? and project_id=? and is_stakeholder=1", array($singe, $project->id));