Skip to content

Commit

Permalink
Updated instance of Table::association()
Browse files Browse the repository at this point in the history
Replaced all instances of Table::association() with Table::getAssociation() in the framework source and tests.
  • Loading branch information
sdustinh committed Nov 7, 2017
1 parent 9438e57 commit 5fa448c
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 100 deletions.
44 changes: 22 additions & 22 deletions src/ORM/Association/BelongsToMany.php
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
]);
Expand Down Expand Up @@ -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(), []);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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));

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1398,7 +1398,7 @@ protected function _junctionAssociationName()
{
if (!$this->_junctionAssociationName) {
$this->_junctionAssociationName = $this->getTarget()
->association($this->junction()->getAlias())
->getAssociation($this->junction()->getAlias())
->getName();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Association/HasMany.php
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Behavior/CounterCacheBehavior.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/EagerLoader.php
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Marshaller.php
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Query.php
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Rule/ExistsIn.php
Expand Up @@ -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'.",
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/SaveOptionsBuilder.php
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 5fa448c

Please sign in to comment.