Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit b178b289c8ad4fdfac3f428c906d52a8049d2638 1 parent a693097
Grafikart Grafikart authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/ORM/Table.php
5 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();
Please sign in to comment.
Something went wrong with that request. Please try again.