php - Save without get lastInsertId -
i have old database in postgresql multiple primary key.
when try save information in these tables, error occurred because cakephp trying lastinsertid. because, know, cakephp doesn't support multiple primary key.
so, wanna know, how can disable functionality/option?
i tried this, doesn't work expected.
$this->orderdrinkbase->saveall( $drinkbases, array('callbacks' => false, 'validate' => false) );
the solution above, works, approved answer. but, want explanation of how can disable function lastinsertid in cakephp in cases.
use following code
class grouptouser extends appmodel { var $name = 'grouptouser'; var $usetable = 'groups_users'; var $primarykeyarray = array('user_id','group_id'); function exists($reset = false) { if (!empty($this->__exists) && $reset !== true) { return $this->__exists; } $conditions = array(); foreach ($this->primarykeyarray $pk) { if (isset($this->data[$this->alias][$pk]) && $this->data[$this->alias][$pk]) { $conditions[$this->alias.'.'.$pk] = $this->data[$this->alias][$pk]; } else { $conditions[$this->alias.'.'.$pk] = 0; } } $query = array('conditions' => $conditions, 'fields' => array($this->alias.'.'.$this->primarykey), 'recursive' => -1, 'callbacks' => false); if (is_array($reset)) { $query = array_merge($query, $reset); } if ($exists = $this->find('first', $query)) { $this->__exists = 1; $this->id = $exists[$this->alias][$this->primarykey]; return true; } else { return parent::exists($reset); } } }
for more information @ here http://mrphp.com.au/blog/multiple-primary-keys-cakephp#.uhxzgd90klq
or http://miljenkobarbir.com/using-multiple-column-primary-key-in-cakephp-cascade-delete-problem/
Comments
Post a Comment