Skip to content
Permalink
Browse files

Using the bindingKey method in BelongsToMany

  • Loading branch information...
lorenzo committed Jul 1, 2015
1 parent 327a284 commit b0bbe8bad8a522e0db865353064e6f6826898b1a
Showing with 9 additions and 9 deletions.
  1. +8 −8 src/ORM/Association/BelongsToMany.php
  2. +1 −1 src/ORM/EagerLoader.php
@@ -348,11 +348,11 @@ public function cascadeDelete(EntityInterface $entity, array $options = [])
return true;
}
$foreignKey = (array)$this->foreignKey();
$primaryKey = (array)$this->source()->primaryKey();
$bindingKey = (array)$this->bindingKey();
$conditions = [];
if ($primaryKey) {
$conditions = array_combine($foreignKey, $entity->extract((array)$primaryKey));
if ($bindingKey) {
$conditions = array_combine($foreignKey, $entity->extract($bindingKey));
}
$table = $this->junction();
@@ -533,7 +533,7 @@ protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $o
$foreignKey = (array)$this->foreignKey();
$assocForeignKey = (array)$belongsTo->foreignKey();
$targetPrimaryKey = (array)$target->primaryKey();
$sourcePrimaryKey = (array)$source->primaryKey();
$bindingKey = (array)$this->bindingKey();
$jointProperty = $this->_junctionProperty;
$junctionAlias = $junction->alias();
@@ -545,7 +545,7 @@ protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $o
$joint->set(array_combine(
$foreignKey,
$sourceEntity->extract($sourcePrimaryKey)
$sourceEntity->extract($bindingKey)
), ['guard' => false]);
$joint->set(array_combine($assocForeignKey, $e->extract($targetPrimaryKey)), ['guard' => false]);
$saved = $junction->save($joint, $options);
@@ -718,10 +718,10 @@ function () use ($sourceEntity, $targetEntities) {
*/
public function replaceLinks(EntityInterface $sourceEntity, array $targetEntities, array $options = [])
{
$primaryKey = (array)$this->source()->primaryKey();
$primaryValue = $sourceEntity->extract($primaryKey);
$bindingKey = (array)$this->bindingKey();
$primaryValue = $sourceEntity->extract($bindingKey);
if (count(array_filter($primaryValue, 'strlen')) !== count($primaryKey)) {
if (count(array_filter($primaryValue, 'strlen')) !== count($bindingKey)) {
$message = 'Could not find primary key value for source entity';
throw new InvalidArgumentException($message);
}
@@ -636,7 +636,7 @@ protected function _collectKeys($external, $query, $statement)
$source = $instance->source();
$keys = $instance->type() === Association::MANY_TO_ONE ?
(array)$instance->foreignKey() :
(array)$source->primaryKey();
(array)$instance->bindingKey();
$alias = $source->alias();
$pkFields = [];

0 comments on commit b0bbe8b

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