atk4 / data

Data Access PHP Framework for SQL & high-latency databases
https://atk4-data.readthedocs.io
MIT License
273 stars 46 forks source link

Reverse Join fails to update record #82

Closed romaninsh closed 8 years ago

romaninsh commented 8 years ago

It appears that the use of $join->id in reveres join is incorrect.

Look at this file: https://github.com/atk4/data/blob/develop/src/Join_SQL.php#L211

With reverse join you are joining like this:

$db->join('contact.user_id');

foreign_field is user_id, and suppose user_id is 2. When you add new record, $join->id is set to lastInsertID:

$this->id = $insert->connection->lastInsertID();

so it holds the value of contact.id, let's say it's 1 for our new record. If you execute delete after, the where() clause can cause deletion of incorrect record:

$delete->where($this->foreign_field, $this->id);

which would render to "where user_id = 1".

romaninsh commented 8 years ago

This should be fixed by #107