From 29719a6eb1cefd9192432cd0df727f6c5edbffd6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 19 Jan 2018 15:02:56 -0500 Subject: [PATCH] Use hasAssociation() instead of getAssociation() --- src/ORM/Association/BelongsToMany.php | 10 +++++----- src/ORM/Marshaller.php | 5 +++-- src/ORM/Query.php | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ORM/Association/BelongsToMany.php b/src/ORM/Association/BelongsToMany.php index 9887f4119f2..58ee737dc67 100644 --- a/src/ORM/Association/BelongsToMany.php +++ b/src/ORM/Association/BelongsToMany.php @@ -354,14 +354,14 @@ protected function _generateTargetAssociations($junction, $source, $target) $junctionAlias = $junction->getAlias(); $sAlias = $source->getAlias(); - if (!$target->getAssociation($junctionAlias)) { + if (!$target->hasAssociation($junctionAlias)) { $target->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getTargetForeignKey(), 'strategy' => $this->_strategy, ]); } - if (!$target->getAssociation($sAlias)) { + if (!$target->hasAssociation($sAlias)) { $target->belongsToMany($sAlias, [ 'sourceTable' => $target, 'targetTable' => $source, @@ -391,7 +391,7 @@ protected function _generateTargetAssociations($junction, $source, $target) protected function _generateSourceAssociations($junction, $source) { $junctionAlias = $junction->getAlias(); - if (!$source->getAssociation($junctionAlias)) { + if (!$source->hasAssociation($junctionAlias)) { $source->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getForeignKey(), @@ -421,13 +421,13 @@ protected function _generateJunctionAssociations($junction, $source, $target) $tAlias = $target->getAlias(); $sAlias = $source->getAlias(); - if (!$junction->getAssociation($tAlias)) { + if (!$junction->hasAssociation($tAlias)) { $junction->belongsTo($tAlias, [ 'foreignKey' => $this->getTargetForeignKey(), 'targetTable' => $target ]); } - if (!$junction->getAssociation($sAlias)) { + if (!$junction->hasAssociation($sAlias)) { $junction->belongsTo($sAlias, [ 'foreignKey' => $this->getForeignKey(), 'targetTable' => $source diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index 870bf62405d..45ae6136c24 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -88,10 +88,9 @@ protected function _buildPropertyMap($data, $options) $key = $nested; $nested = []; } - $assoc = $this->_table->getAssociation($key); // If the key is not a special field like _ids or _joinData // it is a missing association that we should error on. - if (!$assoc) { + if (!$this->_table->hasAssociation($key)) { if (substr($key, 0, 1) !== '_') { throw new \InvalidArgumentException(sprintf( 'Cannot marshal data for "%s" association. It is not associated with "%s".', @@ -101,6 +100,8 @@ protected function _buildPropertyMap($data, $options) } continue; } + $assoc = $this->_table->getAssociation($key); + if (isset($options['forceNew'])) { $nested['forceNew'] = $options['forceNew']; } diff --git a/src/ORM/Query.php b/src/ORM/Query.php index e0045148978..801413a428c 100644 --- a/src/ORM/Query.php +++ b/src/ORM/Query.php @@ -437,10 +437,10 @@ public function clearContain() protected function _addAssociationsToTypeMap($table, $typeMap, $associations) { foreach ($associations as $name => $nested) { - $association = $table->getAssociation($name); - if (!$association) { + if (!$table->hasAssociation($name)) { continue; } + $association = $table->getAssociation($name); $target = $association->getTarget(); $primary = (array)$target->getPrimaryKey(); if (empty($primary) || $typeMap->type($target->aliasField($primary[0])) === null) {