Skip to content
Permalink
Browse files

Making BelongsToMany::save() tests pass when using a table with

composite primary key
  • Loading branch information...
lorenzo committed Jan 11, 2014
1 parent 282a648 commit b2e2dcbd542e43f0ea0c8bbd47940c3377cee663
Showing with 4 additions and 3 deletions.
  1. +4 −3 Cake/ORM/Table.php
@@ -1185,7 +1185,8 @@ protected function _insert($entity, $data) {
$keys = array_fill(0, count($primary), null);
$id = (array)$this->_newId($primary) + $keys;
$primary = array_combine($primary, $id);
$data = array_filter($primary, 'strlen') + $data;
$filteredKeys = array_filter($primary, 'strlen');
$data = $filteredKeys + $data;
$statement = $this->query()->insert(array_keys($data))
->values($data)
@@ -1194,8 +1195,8 @@ protected function _insert($entity, $data) {
$success = false;
if ($statement->rowCount() > 0) {
$success = $entity;
$entity->set($primary, ['guard' => false]);
foreach ($primary as $key => $value) {
$entity->set($filteredKeys, ['guard' => false]);
foreach ($primary as $key => $v) {
if (!isset($data[$key])) {
$id = $statement->lastInsertId($this->table(), $key);
$entity->set($key, $id);

0 comments on commit b2e2dcb

Please sign in to comment.
You can’t perform that action at this time.