Permalink
Browse files

Add Table alias before primarykeys for Table::get()

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...
1 parent a693097 commit b178b289c8ad4fdfac3f428c906d52a8049d2638 @Grafikart Grafikart committed Jan 29, 2014
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/ORM/Table.php
View
@@ -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();

0 comments on commit b178b28

Please sign in to comment.