diff --git a/src/ORM/Association/BelongsToMany.php b/src/ORM/Association/BelongsToMany.php index b94be2034fb..3114e4dd453 100644 --- a/src/ORM/Association/BelongsToMany.php +++ b/src/ORM/Association/BelongsToMany.php @@ -346,14 +346,14 @@ protected function _generateTargetAssociations($junction, $source, $target) $junctionAlias = $junction->getAlias(); $sAlias = $source->getAlias(); - if (!$target->association($junctionAlias)) { + if (!$target->getAssociation($junctionAlias)) { $target->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getTargetForeignKey(), 'strategy' => $this->_strategy, ]); } - if (!$target->association($sAlias)) { + if (!$target->getAssociation($sAlias)) { $target->belongsToMany($sAlias, [ 'sourceTable' => $target, 'targetTable' => $source, @@ -383,7 +383,7 @@ protected function _generateTargetAssociations($junction, $source, $target) protected function _generateSourceAssociations($junction, $source) { $junctionAlias = $junction->getAlias(); - if (!$source->association($junctionAlias)) { + if (!$source->getAssociation($junctionAlias)) { $source->hasMany($junctionAlias, [ 'targetTable' => $junction, 'foreignKey' => $this->getForeignKey(), @@ -413,13 +413,13 @@ protected function _generateJunctionAssociations($junction, $source, $target) $tAlias = $target->getAlias(); $sAlias = $source->getAlias(); - if (!$junction->association($tAlias)) { + if (!$junction->getAssociation($tAlias)) { $junction->belongsTo($tAlias, [ 'foreignKey' => $this->getTargetForeignKey(), 'targetTable' => $target ]); } - if (!$junction->association($sAlias)) { + if (!$junction->getAssociation($sAlias)) { $junction->belongsTo($sAlias, [ 'foreignKey' => $this->getForeignKey(), 'targetTable' => $source @@ -453,7 +453,7 @@ public function attachTo(Query $query, array $options = []) } $junction = $this->junction(); - $belongsTo = $junction->association($this->getSource()->getAlias()); + $belongsTo = $junction->getAssociation($this->getSource()->getAlias()); $cond = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->getForeignKey()]); $cond += $this->junctionConditions(); @@ -463,7 +463,7 @@ public function attachTo(Query $query, array $options = []) } // Attach the junction table as well we need it to populate _joinData. - $assoc = $this->_targetTable->association($junction->getAlias()); + $assoc = $this->_targetTable->getAssociation($junction->getAlias()); $newOptions = array_intersect_key($options, ['joinType' => 1, 'fields' => 1]); $newOptions += [ 'conditions' => $cond, @@ -492,7 +492,7 @@ protected function _appendNotMatching($query, $options) $options['conditions'] = []; } $junction = $this->junction(); - $belongsTo = $junction->association($this->getSource()->getAlias()); + $belongsTo = $junction->getAssociation($this->getSource()->getAlias()); $conds = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->getForeignKey()]); $subquery = $this->find() @@ -504,7 +504,7 @@ protected function _appendNotMatching($query, $options) $subquery = $options['queryBuilder']($subquery); } - $assoc = $junction->association($this->getTarget()->getAlias()); + $assoc = $junction->getAssociation($this->getTarget()->getAlias()); $conditions = $assoc->_joinCondition([ 'foreignKey' => $this->getTargetForeignKey() ]); @@ -567,7 +567,7 @@ public function eagerLoader(array $options) 'sort' => $this->getSort(), 'junctionAssociationName' => $name, 'junctionProperty' => $this->_junctionProperty, - 'junctionAssoc' => $this->getTarget()->association($name), + 'junctionAssoc' => $this->getTarget()->getAssociation($name), 'junctionConditions' => $this->junctionConditions(), 'finder' => function () { return $this->_appendJunctionJoin($this->find(), []); @@ -598,7 +598,7 @@ public function cascadeDelete(EntityInterface $entity, array $options = []) } $table = $this->junction(); - $hasMany = $this->getSource()->association($table->getAlias()); + $hasMany = $this->getSource()->getAssociation($table->getAlias()); if ($this->_cascadeCallbacks) { foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) { $table->delete($related, $options); @@ -806,7 +806,7 @@ protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $o $target = $this->getTarget(); $junction = $this->junction(); $entityClass = $junction->getEntityClass(); - $belongsTo = $junction->association($target->getAlias()); + $belongsTo = $junction->getAssociation($target->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); $targetPrimaryKey = (array)$target->getPrimaryKey(); @@ -863,7 +863,7 @@ protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $o * * ``` * $newTags = $tags->find('relevant')->toArray(); - * $articles->association('tags')->link($article, $newTags); + * $articles->getAssociation('tags')->link($article, $newTags); * ``` * * `$article->get('tags')` will contain all tags in `$newTags` after liking @@ -913,7 +913,7 @@ function () use ($sourceEntity, $targetEntities, $options) { * ``` * $article->tags = [$tag1, $tag2, $tag3, $tag4]; * $tags = [$tag1, $tag2, $tag3]; - * $articles->association('tags')->unlink($article, $tags); + * $articles->getAssociation('tags')->unlink($article, $tags); * ``` * * `$article->get('tags')` will contain only `[$tag4]` after deleting in the database @@ -1097,7 +1097,7 @@ public function find($type = null, array $options = []) return $query; } - $belongsTo = $this->junction()->association($this->getTarget()->getAlias()); + $belongsTo = $this->junction()->getAssociation($this->getTarget()->getAlias()); $conditions = $belongsTo->_joinCondition([ 'foreignKey' => $this->getTargetForeignKey() ]); @@ -1125,7 +1125,7 @@ protected function _appendJunctionJoin($query, $conditions) ] ]; - $assoc = $this->getTarget()->association($name); + $assoc = $this->getTarget()->getAssociation($name); $query ->addDefaultTypes($assoc->getTarget()) ->join($matching + $joins, [], true); @@ -1168,7 +1168,7 @@ protected function _appendJunctionJoin($query, $conditions) * $article->tags = [$tag1, $tag2, $tag3, $tag4]; * $articles->save($article); * $tags = [$tag1, $tag3]; - * $articles->association('tags')->replaceLinks($article, $tags); + * $articles->getAssociation('tags')->replaceLinks($article, $tags); * ``` * * `$article->get('tags')` will contain only `[$tag1, $tag3]` at the end @@ -1195,7 +1195,7 @@ public function replaceLinks(EntityInterface $sourceEntity, array $targetEntitie return $this->junction()->getConnection()->transactional( function () use ($sourceEntity, $targetEntities, $primaryValue, $options) { $foreignKey = array_map([$this->_junctionTable, 'aliasField'], (array)$this->getForeignKey()); - $hasMany = $this->getSource()->association($this->_junctionTable->getAlias()); + $hasMany = $this->getSource()->getAssociation($this->_junctionTable->getAlias()); $existing = $hasMany->find('all') ->where(array_combine($foreignKey, $primaryValue)); @@ -1247,7 +1247,7 @@ protected function _diffLinks($existing, $jointEntities, $targetEntities, $optio { $junction = $this->junction(); $target = $this->getTarget(); - $belongsTo = $junction->association($target->getAlias()); + $belongsTo = $junction->getAssociation($target->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); @@ -1367,8 +1367,8 @@ protected function _collectJointEntities($sourceEntity, $targetEntities) return $result; } - $belongsTo = $junction->association($target->getAlias()); - $hasMany = $source->association($junction->getAlias()); + $belongsTo = $junction->getAssociation($target->getAlias()); + $hasMany = $source->getAssociation($junction->getAlias()); $foreignKey = (array)$this->getForeignKey(); $assocForeignKey = (array)$belongsTo->getForeignKey(); $sourceKey = $sourceEntity->extract((array)$source->getPrimaryKey()); @@ -1398,7 +1398,7 @@ protected function _junctionAssociationName() { if (!$this->_junctionAssociationName) { $this->_junctionAssociationName = $this->getTarget() - ->association($this->junction()->getAlias()) + ->getAssociation($this->junction()->getAlias()) ->getName(); } diff --git a/src/ORM/Association/HasMany.php b/src/ORM/Association/HasMany.php index c7d1b4d3a62..454a8034cde 100644 --- a/src/ORM/Association/HasMany.php +++ b/src/ORM/Association/HasMany.php @@ -424,7 +424,7 @@ function ($assoc) use ($targetEntities) { * $author->articles = [$article1, $article2, $article3, $article4]; * $authors->save($author); * $articles = [$article1, $article3]; - * $authors->association('articles')->replace($author, $articles); + * $authors->getAssociation('articles')->replace($author, $articles); * ``` * * `$author->get('articles')` will contain only `[$article1, $article3]` at the end diff --git a/src/ORM/Behavior/CounterCacheBehavior.php b/src/ORM/Behavior/CounterCacheBehavior.php index 17abc550291..2971b3623a6 100644 --- a/src/ORM/Behavior/CounterCacheBehavior.php +++ b/src/ORM/Behavior/CounterCacheBehavior.php @@ -122,7 +122,7 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o } foreach ($this->_config as $assoc => $settings) { - $assoc = $this->_table->association($assoc); + $assoc = $this->_table->getAssociation($assoc); foreach ($settings as $field => $config) { if (is_int($field)) { continue; @@ -191,7 +191,7 @@ public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $ protected function _processAssociations(Event $event, EntityInterface $entity) { foreach ($this->_config as $assoc => $settings) { - $assoc = $this->_table->association($assoc); + $assoc = $this->_table->getAssociation($assoc); $this->_processAssociation($event, $entity, $assoc, $settings); } } diff --git a/src/ORM/Behavior/TranslateBehavior.php b/src/ORM/Behavior/TranslateBehavior.php index c61d4aec13d..eb00b216f11 100644 --- a/src/ORM/Behavior/TranslateBehavior.php +++ b/src/ORM/Behavior/TranslateBehavior.php @@ -696,7 +696,7 @@ protected function _unsetEmptyFields(EntityInterface $entity) */ protected function _findExistingTranslations($ruleSet) { - $association = $this->_table->association($this->_translationTable->getAlias()); + $association = $this->_table->getAssociation($this->_translationTable->getAlias()); $query = $association->find() ->select(['id', 'num' => 0]) diff --git a/src/ORM/EagerLoader.php b/src/ORM/EagerLoader.php index 77f80736473..54dff1515a0 100644 --- a/src/ORM/EagerLoader.php +++ b/src/ORM/EagerLoader.php @@ -508,7 +508,7 @@ public function externalAssociations(Table $repository) protected function _normalizeContain(Table $parent, $alias, $options, $paths) { $defaults = $this->_containOptions; - $instance = $parent->association($alias); + $instance = $parent->getAssociation($alias); if (!$instance) { throw new InvalidArgumentException( sprintf('%s is not associated with %s', $parent->getAlias(), $alias) diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index 3326baba366..eabd4c78291 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -88,7 +88,7 @@ protected function _buildPropertyMap($data, $options) $key = $nested; $nested = []; } - $assoc = $this->_table->association($key); + $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) { diff --git a/src/ORM/Query.php b/src/ORM/Query.php index d592999d953..61c502ee27f 100644 --- a/src/ORM/Query.php +++ b/src/ORM/Query.php @@ -433,7 +433,7 @@ public function clearContain() protected function _addAssociationsToTypeMap($table, $typeMap, $associations) { foreach ($associations as $name => $nested) { - $association = $table->association($name); + $association = $table->getAssociation($name); if (!$association) { continue; } diff --git a/src/ORM/Rule/ExistsIn.php b/src/ORM/Rule/ExistsIn.php index 1eea45e50d2..bf0e4d37f9c 100644 --- a/src/ORM/Rule/ExistsIn.php +++ b/src/ORM/Rule/ExistsIn.php @@ -80,7 +80,7 @@ public function __construct($fields, $repository, array $options = []) public function __invoke(EntityInterface $entity, array $options) { if (is_string($this->_repository)) { - $repository = $options['repository']->association($this->_repository); + $repository = $options['repository']->getAssociation($this->_repository); if (!$repository) { throw new RuntimeException(sprintf( "ExistsIn rule for '%s' is invalid. '%s' is not associated with '%s'.", diff --git a/src/ORM/SaveOptionsBuilder.php b/src/ORM/SaveOptionsBuilder.php index 97e1ed2fe9c..f3ea0b95cc2 100644 --- a/src/ORM/SaveOptionsBuilder.php +++ b/src/ORM/SaveOptionsBuilder.php @@ -107,7 +107,7 @@ protected function _associated(Table $table, array $associations) } $this->_checkAssociation($table, $key); if (isset($associated['associated'])) { - $this->_associated($table->association($key)->getTarget(), $associated['associated']); + $this->_associated($table->getAssociation($key)->getTarget(), $associated['associated']); continue; } } diff --git a/tests/TestCase/ORM/Association/BelongsToManyTest.php b/tests/TestCase/ORM/Association/BelongsToManyTest.php index c105acb0796..ab8feef349a 100644 --- a/tests/TestCase/ORM/Association/BelongsToManyTest.php +++ b/tests/TestCase/ORM/Association/BelongsToManyTest.php @@ -150,20 +150,20 @@ public function testJunction() $this->assertInstanceOf('Cake\ORM\Table', $junction); $this->assertEquals('ArticlesTags', $junction->alias()); $this->assertEquals('articles_tags', $junction->table()); - $this->assertSame($this->article, $junction->association('Articles')->target()); - $this->assertSame($this->tag, $junction->association('Tags')->target()); + $this->assertSame($this->article, $junction->getAssociation('Articles')->target()); + $this->assertSame($this->tag, $junction->getAssociation('Tags')->target()); $belongsTo = '\Cake\ORM\Association\BelongsTo'; - $this->assertInstanceOf($belongsTo, $junction->association('Articles')); - $this->assertInstanceOf($belongsTo, $junction->association('Tags')); + $this->assertInstanceOf($belongsTo, $junction->getAssociation('Articles')); + $this->assertInstanceOf($belongsTo, $junction->getAssociation('Tags')); - $this->assertSame($junction, $this->tag->association('ArticlesTags')->target()); - $this->assertSame($this->article, $this->tag->association('Articles')->target()); + $this->assertSame($junction, $this->tag->getAssociation('ArticlesTags')->target()); + $this->assertSame($this->article, $this->tag->getAssociation('Articles')->target()); $hasMany = '\Cake\ORM\Association\HasMany'; $belongsToMany = '\Cake\ORM\Association\BelongsToMany'; - $this->assertInstanceOf($belongsToMany, $this->tag->association('Articles')); - $this->assertInstanceOf($hasMany, $this->tag->association('ArticlesTags')); + $this->assertInstanceOf($belongsToMany, $this->tag->getAssociation('Articles')); + $this->assertInstanceOf($hasMany, $this->tag->getAssociation('ArticlesTags')); $this->assertSame($junction, $assoc->junction()); $junction2 = TableRegistry::get('Foos'); @@ -173,9 +173,9 @@ public function testJunction() $assoc->junction('ArticlesTags'); $this->assertSame($junction, $assoc->junction()); - $this->assertSame($assoc->strategy(), $this->tag->association('Articles')->strategy()); - $this->assertSame($assoc->strategy(), $this->tag->association('ArticlesTags')->strategy()); - $this->assertSame($assoc->strategy(), $this->article->association('ArticlesTags')->strategy()); + $this->assertSame($assoc->strategy(), $this->tag->getAssociation('Articles')->strategy()); + $this->assertSame($assoc->strategy(), $this->tag->getAssociation('ArticlesTags')->strategy()); + $this->assertSame($assoc->strategy(), $this->article->getAssociation('ArticlesTags')->strategy()); } /** @@ -218,13 +218,13 @@ public function testJunctionCustomKeys() 'foreignKey' => 'tag', 'targetForeignKey' => 'article' ]); - $junction = $this->article->association('Tags')->junction(); - $this->assertEquals('article', $junction->association('Articles')->foreignKey()); - $this->assertEquals('article', $this->article->association('ArticlesTags')->foreignKey()); + $junction = $this->article->getAssociation('Tags')->junction(); + $this->assertEquals('article', $junction->getAssociation('Articles')->foreignKey()); + $this->assertEquals('article', $this->article->getAssociation('ArticlesTags')->foreignKey()); - $junction = $this->tag->association('Articles')->junction(); - $this->assertEquals('tag', $junction->association('Tags')->foreignKey()); - $this->assertEquals('tag', $this->tag->association('ArticlesTags')->foreignKey()); + $junction = $this->tag->getAssociation('Articles')->junction(); + $this->assertEquals('tag', $junction->getAssociation('Tags')->foreignKey()); + $this->assertEquals('tag', $this->tag->getAssociation('ArticlesTags')->foreignKey()); } /** @@ -300,7 +300,7 @@ public function testCascadeDelete() $association = new BelongsToMany('Tags', $config); $association->junction($articleTag); $this->article - ->association($articleTag->alias()) + ->getAssociation($articleTag->alias()) ->conditions(['click_count' => 3]); $articleTag->expects($this->once()) @@ -333,7 +333,7 @@ public function testCascadeDeleteDependent() $association = new BelongsToMany('Tags', $config); $association->junction($articleTag); $this->article - ->association($articleTag->alias()) + ->getAssociation($articleTag->alias()) ->conditions(['click_count' => 3]); $articleTag->expects($this->never()) @@ -360,7 +360,7 @@ public function testCascadeDeleteWithCallbacks() ]; $association = new BelongsToMany('Tag', $config); $association->junction($articleTag); - $this->article->association($articleTag->alias()); + $this->article->getAssociation($articleTag->alias()); $counter = $this->getMockBuilder('StdClass') ->setMethods(['__invoke']) @@ -1037,10 +1037,10 @@ public function testJunctionWithCustomForeignKeys() 'targetForeignKey' => 'Tag' ]); $junction = $assoc->junction(); - $this->assertEquals('Art', $junction->association('Articles')->foreignKey()); - $this->assertEquals('Tag', $junction->association('Tags')->foreignKey()); + $this->assertEquals('Art', $junction->getAssociation('Articles')->foreignKey()); + $this->assertEquals('Tag', $junction->getAssociation('Tags')->foreignKey()); - $inverseRelation = $this->tag->association('Articles'); + $inverseRelation = $this->tag->getAssociation('Articles'); $this->assertEquals('Tag', $inverseRelation->foreignKey()); $this->assertEquals('Art', $inverseRelation->targetForeignKey()); } @@ -1096,25 +1096,25 @@ public function testGeneratedAssociations() // Generate associations $assoc->junction(); - $tagAssoc = $articles->association('Tags'); + $tagAssoc = $articles->getAssociation('Tags'); $this->assertNotEmpty($tagAssoc, 'btm should exist'); $this->assertEquals($conditions, $tagAssoc->conditions()); $this->assertEquals('target_foreign_key', $tagAssoc->targetForeignKey()); $this->assertEquals('foreign_key', $tagAssoc->foreignKey()); - $jointAssoc = $articles->association('SpecialTags'); + $jointAssoc = $articles->getAssociation('SpecialTags'); $this->assertNotEmpty($jointAssoc, 'has many to junction should exist'); $this->assertInstanceOf('Cake\ORM\Association\HasMany', $jointAssoc); $this->assertEquals('foreign_key', $jointAssoc->foreignKey()); - $articleAssoc = $tags->association('Articles'); + $articleAssoc = $tags->getAssociation('Articles'); $this->assertNotEmpty($articleAssoc, 'reverse btm should exist'); $this->assertInstanceOf('Cake\ORM\Association\BelongsToMany', $articleAssoc); $this->assertEquals($conditions, $articleAssoc->conditions()); $this->assertEquals('foreign_key', $articleAssoc->targetForeignKey(), 'keys should swap'); $this->assertEquals('target_foreign_key', $articleAssoc->foreignKey(), 'keys should swap'); - $jointAssoc = $tags->association('SpecialTags'); + $jointAssoc = $tags->getAssociation('SpecialTags'); $this->assertNotEmpty($jointAssoc, 'has many to junction should exist'); $this->assertInstanceOf('Cake\ORM\Association\HasMany', $jointAssoc); $this->assertEquals('target_foreign_key', $jointAssoc->foreignKey()); diff --git a/tests/TestCase/ORM/AssociationProxyTest.php b/tests/TestCase/ORM/AssociationProxyTest.php index d8ab30293bf..2d43131504d 100644 --- a/tests/TestCase/ORM/AssociationProxyTest.php +++ b/tests/TestCase/ORM/AssociationProxyTest.php @@ -58,8 +58,8 @@ public function testAssociationAsProperty() $this->assertTrue(isset($articles->authors)); $this->assertTrue(isset($articles->comments)); $this->assertFalse(isset($articles->posts)); - $this->assertSame($articles->association('authors'), $articles->authors); - $this->assertSame($articles->association('comments'), $articles->comments); + $this->assertSame($articles->getAssociation('authors'), $articles->authors); + $this->assertSame($articles->getAssociation('comments'), $articles->comments); } /** @@ -133,7 +133,7 @@ public function testAssociationAsPropertyProxy() $articles->belongsTo('authors'); $authors->hasMany('comments'); $this->assertTrue(isset($articles->authors->comments)); - $this->assertSame($authors->association('comments'), $articles->authors->comments); + $this->assertSame($authors->getAssociation('comments'), $articles->authors->comments); } /** diff --git a/tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php b/tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php index bb6b0ffbdaf..9557a9c9c49 100644 --- a/tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php +++ b/tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php @@ -440,7 +440,7 @@ public function testBindingKey() 'bindingKey' => ['category_id', 'user_id'], 'foreignKey' => ['category_id', 'user_id'] ]); - $this->post->association('UserCategoryPosts')->target($this->userCategoryPosts); + $this->post->getAssociation('UserCategoryPosts')->target($this->userCategoryPosts); $this->post->addBehavior('CounterCache', [ 'UserCategoryPosts' => ['post_count'] ]); diff --git a/tests/TestCase/ORM/CompositeKeysTest.php b/tests/TestCase/ORM/CompositeKeysTest.php index 7bdd83db3bc..1ff96bcba54 100644 --- a/tests/TestCase/ORM/CompositeKeysTest.php +++ b/tests/TestCase/ORM/CompositeKeysTest.php @@ -212,7 +212,7 @@ public function testHasManyEager($strategy) ->toArray(); $expected[0]['articles'] = []; $this->assertEquals($expected, $results); - $this->assertEquals($table->association('SiteArticles')->strategy(), $strategy); + $this->assertEquals($table->getAssociation('SiteArticles')->strategy(), $strategy); } /** @@ -301,7 +301,7 @@ public function testBelongsToManyEager($strategy) ], ]; $this->assertEquals($expected, $results); - $this->assertEquals($articles->association('SiteTags')->strategy(), $strategy); + $this->assertEquals($articles->getAssociation('SiteTags')->strategy(), $strategy); } /** @@ -481,7 +481,7 @@ public function testDeleteDependent() $entity = $table->get([3, 2]); $result = $table->delete($entity); - $query = $table->association('SiteArticles')->find('all', [ + $query = $table->getAssociation('SiteArticles')->find('all', [ 'conditions' => [ 'author_id' => $entity->id, 'site_id' => $entity->site_id diff --git a/tests/TestCase/ORM/QueryRegressionTest.php b/tests/TestCase/ORM/QueryRegressionTest.php index 2fb04d3ba82..e94fcfdb2f7 100644 --- a/tests/TestCase/ORM/QueryRegressionTest.php +++ b/tests/TestCase/ORM/QueryRegressionTest.php @@ -1704,9 +1704,9 @@ public function testFormatDeepDistantAssociationRecords2() $this->loadFixtures('Authors', 'Articles', 'Tags', 'ArticlesTags'); $table = TableRegistry::get('authors'); $table->hasMany('articles'); - $articles = $table->association('articles')->target(); + $articles = $table->getAssociation('articles')->target(); $articles->hasMany('articlesTags'); - $tags = $articles->association('articlesTags')->target()->belongsTo('tags'); + $tags = $articles->getAssociation('articlesTags')->target()->belongsTo('tags'); $tags->target()->getEventManager()->on('Model.beforeFind', function ($e, $query) { return $query->formatResults(function ($results) { diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 7c694413f75..525252fdc5c 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -273,7 +273,7 @@ public function testHasManyEagerLoadingNoHydration($strategy) ->toArray(); $expected[0]['articles'] = []; $this->assertEquals($expected, $results); - $this->assertEquals($table->association('articles')->strategy(), $strategy); + $this->assertEquals($table->getAssociation('articles')->strategy(), $strategy); } /** @@ -657,7 +657,7 @@ public function testBelongsToManyEagerLoadingNoHydration($strategy) ], ]; $this->assertEquals($expected, $results); - $this->assertEquals($table->association('Tags')->strategy(), $strategy); + $this->assertEquals($table->getAssociation('Tags')->strategy(), $strategy); } /** @@ -2323,7 +2323,7 @@ public function testFormatDeepAssociationRecords() { $table = TableRegistry::get('ArticlesTags'); $table->belongsTo('Articles'); - $table->association('Articles')->target()->belongsTo('Authors'); + $table->getAssociation('Articles')->target()->belongsTo('Authors'); $builder = function ($q) { return $q @@ -2371,9 +2371,9 @@ public function testFormatDeepDistantAssociationRecords() { $table = TableRegistry::get('authors'); $table->hasMany('articles'); - $articles = $table->association('articles')->target(); + $articles = $table->getAssociation('articles')->target(); $articles->hasMany('articlesTags'); - $articles->association('articlesTags')->target()->belongsTo('tags'); + $articles->getAssociation('articlesTags')->target()->belongsTo('tags'); $query = $table->find()->contain(['articles.articlesTags.tags' => function ($q) { return $q->formatResults(function ($results) { @@ -2447,7 +2447,7 @@ public function testContainInAssociationQuery() { $table = TableRegistry::get('ArticlesTags'); $table->belongsTo('Articles'); - $table->association('Articles')->target()->belongsTo('Authors'); + $table->getAssociation('Articles')->target()->belongsTo('Authors'); $query = $table->find() ->order(['Articles.id' => 'ASC']) @@ -2469,9 +2469,9 @@ public function testContainInAssociationMatching() { $table = TableRegistry::get('authors'); $table->hasMany('articles'); - $articles = $table->association('articles')->target(); + $articles = $table->getAssociation('articles')->target(); $articles->hasMany('articlesTags'); - $articles->association('articlesTags')->target()->belongsTo('tags'); + $articles->getAssociation('articlesTags')->target()->belongsTo('tags'); $query = $table->find()->matching('articles.articlesTags', function ($q) { return $q->matching('tags', function ($q) { diff --git a/tests/TestCase/ORM/RulesCheckerIntegrationTest.php b/tests/TestCase/ORM/RulesCheckerIntegrationTest.php index 452fa45a0d4..dad20a66d13 100644 --- a/tests/TestCase/ORM/RulesCheckerIntegrationTest.php +++ b/tests/TestCase/ORM/RulesCheckerIntegrationTest.php @@ -65,12 +65,12 @@ public function testsSaveBelongsToWithValidationError() $table = TableRegistry::get('articles'); $table->belongsTo('authors'); - $table->association('authors') + $table->getAssociation('authors') ->target() ->rulesChecker() ->add( function (Entity $author, array $options) use ($table) { - $this->assertSame($options['repository'], $table->association('authors')->target()); + $this->assertSame($options['repository'], $table->getAssociation('authors')->target()); return false; }, @@ -104,7 +104,7 @@ public function testSaveHasOneWithValidationError() $table = TableRegistry::get('authors'); $table->hasOne('articles'); - $table->association('articles') + $table->getAssociation('articles') ->target() ->rulesChecker() ->add( @@ -149,7 +149,7 @@ public function testSaveHasManyWithErrorsAtomic() $table = TableRegistry::get('authors'); $table->hasMany('articles'); - $table->association('articles') + $table->getAssociation('articles') ->target() ->rulesChecker() ->add( @@ -198,7 +198,7 @@ public function testSaveHasManyWithErrorsNonAtomic() $table = TableRegistry::get('authors'); $table->hasMany('articles'); - $table->association('articles') + $table->getAssociation('articles') ->target() ->rulesChecker() ->add( @@ -240,7 +240,7 @@ public function testSaveBelongsToManyWithValidationErrorInJointEntity() ]; $table = TableRegistry::get('articles'); $table->belongsToMany('tags'); - $table->association('tags') + $table->getAssociation('tags') ->junction() ->rulesChecker() ->add(function (Entity $entity) { @@ -280,7 +280,7 @@ public function testSaveBelongsToManyWithValidationErrorInJointEntityNonAtomic() ]; $table = TableRegistry::get('articles'); $table->belongsToMany('tags'); - $table->association('tags') + $table->getAssociation('tags') ->junction() ->rulesChecker() ->add(function (Entity $entity) { @@ -1319,8 +1319,8 @@ public function testAvoidExistsInOnAutomaticSaving() $table = TableRegistry::get('authors'); $table->hasMany('articles'); - $table->association('articles')->belongsTo('authors'); - $checker = $table->association('articles')->target()->rulesChecker(); + $table->getAssociation('articles')->belongsTo('authors'); + $checker = $table->getAssociation('articles')->target()->rulesChecker(); $checker->add(function ($entity, $options) use ($checker) { $rule = $checker->existsIn('author_id', 'authors'); $id = $entity->author_id; diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index 9cad7cc49b7..61f7b1fa9a0 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -545,7 +545,7 @@ public function testBelongsTo() $table = new Table(['table' => 'dates']); $belongsTo = $table->belongsTo('user', $options); $this->assertInstanceOf('Cake\ORM\Association\BelongsTo', $belongsTo); - $this->assertSame($belongsTo, $table->association('user')); + $this->assertSame($belongsTo, $table->getAssociation('user')); $this->assertEquals('user', $belongsTo->name()); $this->assertEquals('fake_id', $belongsTo->foreignKey()); $this->assertEquals(['a' => 'b'], $belongsTo->conditions()); @@ -563,7 +563,7 @@ public function testHasOne() $table = new Table(['table' => 'users']); $hasOne = $table->hasOne('profile', $options); $this->assertInstanceOf('Cake\ORM\Association\HasOne', $hasOne); - $this->assertSame($hasOne, $table->association('profile')); + $this->assertSame($hasOne, $table->getAssociation('profile')); $this->assertEquals('profile', $hasOne->name()); $this->assertEquals('user_id', $hasOne->foreignKey()); $this->assertEquals(['b' => 'c'], $hasOne->conditions()); @@ -694,7 +694,7 @@ public function testHasMany() $table = new Table(['table' => 'authors']); $hasMany = $table->hasMany('article', $options); $this->assertInstanceOf('Cake\ORM\Association\HasMany', $hasMany); - $this->assertSame($hasMany, $table->association('article')); + $this->assertSame($hasMany, $table->getAssociation('article')); $this->assertEquals('article', $hasMany->name()); $this->assertEquals('author_id', $hasMany->foreignKey()); $this->assertEquals(['b' => 'c'], $hasMany->conditions()); @@ -812,7 +812,7 @@ public function testBelongsToMany() $table = new Table(['table' => 'authors', 'connection' => $this->connection]); $belongsToMany = $table->belongsToMany('tag', $options); $this->assertInstanceOf('Cake\ORM\Association\BelongsToMany', $belongsToMany); - $this->assertSame($belongsToMany, $table->association('tag')); + $this->assertSame($belongsToMany, $table->getAssociation('tag')); $this->assertEquals('tag', $belongsToMany->name()); $this->assertEquals('thing_id', $belongsToMany->foreignKey()); $this->assertEquals(['b' => 'c'], $belongsToMany->conditions()); @@ -1948,7 +1948,7 @@ public function testSaveDefaultSaveStrategy() ] ); $authors->hasMany('Articles', ['saveStrategy' => 'append']); - $this->assertEquals('append', $authors->association('articles')->saveStrategy()); + $this->assertEquals('append', $authors->getAssociation('articles')->saveStrategy()); } /** @@ -3046,7 +3046,7 @@ public function testDeleteDependent() $entity = $table->get(1); $result = $table->delete($entity); - $articles = $table->association('articles')->target(); + $articles = $table->getAssociation('articles')->target(); $query = $articles->find('all', [ 'conditions' => [ 'author_id' => $entity->id @@ -3091,7 +3091,7 @@ public function testDeleteNoDependentNoCascade() $entity = $query->first(); $result = $table->delete($entity); - $articles = $table->association('articles')->target(); + $articles = $table->getAssociation('articles')->target(); $query = $articles->find('all')->where(['author_id' => $entity->id]); $this->assertCount(2, $query->execute(), 'Should find rows.'); } @@ -3112,7 +3112,7 @@ public function testDeleteBelongsToMany() $entity = $query->first(); $table->delete($entity); - $junction = $table->association('tags')->junction(); + $junction = $table->getAssociation('tags')->junction(); $query = $junction->find('all')->where(['article_id' => 1]); $this->assertNull($query->all()->first(), 'Should not find any rows.'); } @@ -4371,7 +4371,7 @@ public function testLinkBelongsToMany() $tags[] = $newTag; $tagsTable->save($newTag); - $table->association('tags')->link($article, $tags); + $table->getAssociation('tags')->link($article, $tags); $this->assertEquals($article->tags, $tags); foreach ($tags as $tag) { @@ -4891,7 +4891,7 @@ public function testUnlinkBelongsToMany() ->where(['id' => 1]) ->contain(['tags'])->first(); - $table->association('tags')->unlink($article, [$article->tags[0]]); + $table->getAssociation('tags')->unlink($article, [$article->tags[0]]); $this->assertCount(1, $article->tags); $this->assertEquals(2, $article->tags[0]->get('id')); $this->assertFalse($article->isDirty('tags')); @@ -4913,7 +4913,7 @@ public function testUnlinkBelongsToManyMultiple() $tags[] = new \TestApp\Model\Entity\Tag(['id' => 1], $options); $tags[] = new \TestApp\Model\Entity\Tag(['id' => 2], $options); - $table->association('tags')->unlink($article, $tags); + $table->getAssociation('tags')->unlink($article, $tags); $left = $table->find('all')->where(['id' => 1])->contain(['tags'])->first(); $this->assertEmpty($left->tags); } @@ -4940,7 +4940,7 @@ public function testUnlinkBelongsToManyPassingJoint() 'tag_id' => 2 ], $options); - $table->association('tags')->unlink($article, $tags); + $table->getAssociation('tags')->unlink($article, $tags); $left = $table->find('all')->where(['id' => 1])->contain(['tags'])->first(); $this->assertEmpty($left->tags); } @@ -4962,7 +4962,7 @@ public function testReplacelinksBelongsToMany() $tags[] = new \TestApp\Model\Entity\Tag(['id' => 3], $options); $tags[] = new \TestApp\Model\Entity\Tag(['name' => 'foo']); - $table->association('tags')->replaceLinks($article, $tags); + $table->getAssociation('tags')->replaceLinks($article, $tags); $this->assertEquals(2, $article->tags[0]->id); $this->assertEquals(3, $article->tags[1]->id); $this->assertEquals(4, $article->tags[2]->id); @@ -4990,7 +4990,7 @@ public function testReplacelinksBelongsToManyWithEmpty() $article = new Entity(['id' => 1], $options); $tags = []; - $table->association('tags')->replaceLinks($article, $tags); + $table->getAssociation('tags')->replaceLinks($article, $tags); $this->assertSame($tags, $article->tags); $article = $table->find('all')->where(['id' => 1])->contain(['tags'])->first(); $this->assertEmpty($article->tags); @@ -5019,7 +5019,7 @@ public function testReplacelinksBelongsToManyWithJoint() ], $options); $tags[] = new \TestApp\Model\Entity\Tag(['id' => 3], $options); - $table->association('tags')->replaceLinks($article, $tags); + $table->getAssociation('tags')->replaceLinks($article, $tags); $this->assertSame($tags, $article->tags); $article = $table->find('all')->where(['id' => 1])->contain(['tags'])->first(); $this->assertCount(2, $article->tags); @@ -6115,7 +6115,7 @@ public function testCallbackArgumentTypes() $eventManager = $table->getEventManager(); $associationBeforeFindCount = 0; - $table->association('authors')->target()->getEventManager()->on( + $table->getAssociation('authors')->target()->getEventManager()->on( 'Model.beforeFind', function (Event $event, Query $query, ArrayObject $options, $primary) use (&$associationBeforeFindCount) { $this->assertTrue(is_bool($primary));