Browse Source

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
Jonathan Boyer 12 years ago
parent
commit
b178b289c8
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/ORM/Table.php

+ 5 - 0
src/ORM/Table.php

@@ -887,6 +887,11 @@ class Table implements EventListener {
  */
 	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();