Skip to content

Commit

Permalink
Add Table alias before primarykeys for Table::get()
Browse files Browse the repository at this point in the history
If get() method is used with contain there is a risk of having a integrity constraint violation :

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
  • Loading branch information
Grafikart committed Jan 29, 2014
1 parent a693097 commit b178b28
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ORM/Table.php
Expand Up @@ -887,6 +887,11 @@ protected function _setFieldMatchers($options, $keys) {
*/
public function get($primaryKey, $options = []) {
$key = (array)$this->primaryKey();
if (!empty($this->_alias)) {
foreach($key as $index => $keyname){
$key[$index] = $this->_alias . '.' . $keyname;
}
}
$conditions = array_combine($key, (array)$primaryKey);
$entity = $this->find('all', $options)->where($conditions)->first();

Expand Down

0 comments on commit b178b28

Please sign in to comment.