From b178b289c8ad4fdfac3f428c906d52a8049d2638 Mon Sep 17 00:00:00 2001 From: Jonathan Boyer Date: Wed, 29 Jan 2014 21:22:18 +0100 Subject: [PATCH] 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 --- src/ORM/Table.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ORM/Table.php b/src/ORM/Table.php index 193920e40df..df631a529eb 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -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();