Skip to content

Commit

Permalink
Merge pull request #10241 from chinpei215/fix-returns-this
Browse files Browse the repository at this point in the history
Remove overridden combined setter/getter methods
  • Loading branch information
markstory committed Feb 17, 2017
2 parents e7515bc + f1c7b72 commit 2200cda
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 83 deletions.
17 changes: 0 additions & 17 deletions src/ORM/Association/BelongsTo.php
Expand Up @@ -55,23 +55,6 @@ public function getForeignKey()
return $this->_foreignKey;
}

/**
* Sets the name of the field representing the foreign key to the target table.
* If no parameters are passed current field is returned
*
* @deprecated 3.4.0 Use setForeignKey()/getForeignKey() instead.
* @param string|null $key the key to be used to link both tables together
* @return string
*/
public function foreignKey($key = null)
{
if ($key !== null) {
$this->setForeignKey($key);
}

return $this->getForeignKey();
}

/**
* Handle cascading deletes.
*
Expand Down
31 changes: 1 addition & 30 deletions src/ORM/Association/BelongsToMany.php
Expand Up @@ -194,7 +194,7 @@ public function getTargetForeignKey()
public function targetForeignKey($key = null)
{
if ($key !== null) {
return $this->setTargetForeignKey($key);
$this->setTargetForeignKey($key);
}

return $this->getTargetForeignKey();
Expand Down Expand Up @@ -226,22 +226,6 @@ public function getForeignKey()
return $this->_foreignKey;
}

/**
* Sets the name of the field representing the foreign key to the source table.
* If no parameters are passed current field is returned
*
* @param string|null $key the key to be used to link both tables together
* @return string
*/
public function foreignKey($key = null)
{
if ($key !== null) {
$this->setForeignKey($key);
}

return $this->getForeignKey();
}

/**
* Sets the sort order in which target records should be returned.
* If no arguments are passed the currently configured value is returned
Expand Down Expand Up @@ -968,19 +952,6 @@ public function setConditions($conditions)
return $this;
}

/**
* {@inheritDoc}
* @deprecated 3.4.0 Use setConditions()/getConditions() instead.
*/
public function conditions($conditions = null)
{
if ($conditions !== null) {
$this->setConditions($conditions);
}

return $this->getConditions();
}

/**
* Sets the current join table, either the name of the Table instance or the instance itself.
*
Expand Down
17 changes: 0 additions & 17 deletions src/ORM/Association/HasMany.php
Expand Up @@ -565,23 +565,6 @@ public function getForeignKey()
return $this->_foreignKey;
}

/**
* Sets the name of the field representing the foreign key to the source table.
* If no parameters are passed current field is returned
*
* @deprecated 3.4.0 Use setForeignKey()/getForeignKey() instead.
* @param string|null $key the key to be used to link both tables together
* @return string
*/
public function foreignKey($key = null)
{
if ($key !== null) {
return $this->setForeignKey($key);
}

return $this->getForeignKey();
}

/**
* Sets the sort order in which target records should be returned.
*
Expand Down
17 changes: 0 additions & 17 deletions src/ORM/Association/HasOne.php
Expand Up @@ -55,23 +55,6 @@ public function getForeignKey()
return $this->_foreignKey;
}

/**
* Sets the name of the field representing the foreign key to the target table.
* If no parameters are passed current field is returned
*
* @deprecated 3.4.0 Use setForeignKey()/getForeignKey() instead.
* @param string|null $key the key to be used to link both tables together
* @return string
*/
public function foreignKey($key = null)
{
if ($key !== null) {
return $this->setForeignKey($key);
}

return $this->getForeignKey();
}

/**
* Returns default property name based on association name.
*
Expand Down
18 changes: 17 additions & 1 deletion tests/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -77,6 +77,22 @@ public function tearDown()
TableRegistry::clear();
}

/**
* Tests that foreignKey() returns the correct configured value
*
* @return void
*/
public function testForeignKey()
{
$assoc = new BelongsToMany('Test', [
'sourceTable' => $this->article,
'targetTable' => $this->tag
]);
$this->assertEquals('article_id', $assoc->foreignKey());
$this->assertEquals('another_key', $assoc->foreignKey('another_key'));
$this->assertEquals('another_key', $assoc->foreignKey());
}

/**
* Tests that the association reports it can be joined
*
Expand Down Expand Up @@ -930,7 +946,7 @@ public function testTargetForeignKey()
'targetTable' => $this->tag
]);
$this->assertEquals('tag_id', $assoc->targetForeignKey());
$assoc->targetForeignKey('another_key');
$this->assertEquals('another_key', $assoc->targetForeignKey('another_key'));
$this->assertEquals('another_key', $assoc->targetForeignKey());

$assoc = new BelongsToMany('Test', [
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/ORM/Association/BelongsToTest.php
Expand Up @@ -89,6 +89,22 @@ public function tearDown()
* @return void
*/
public function testForeignKey()
{
$assoc = new BelongsTo('Companies', [
'sourceTable' => $this->client,
'targetTable' => $this->company,
]);
$this->assertEquals('company_id', $assoc->foreignKey());
$this->assertEquals('another_key', $assoc->foreignKey('another_key'));
$this->assertEquals('another_key', $assoc->foreignKey());
}

/**
* Test that foreignKey generation ignores database names in target table.
*
* @return void
*/
public function testForeignKeyIgnoreDatabaseName()
{
$this->company->table('schema.companies');
$this->client->table('schema.clients');
Expand Down
17 changes: 16 additions & 1 deletion tests/TestCase/ORM/Association/HasManyTest.php
Expand Up @@ -95,11 +95,26 @@ public function tearDown()
}

/**
* Test that foreignKey generation ignores database names in target table.
* Tests that foreignKey() returns the correct configured value
*
* @return void
*/
public function testForeignKey()
{
$assoc = new HasMany('Articles', [
'sourceTable' => $this->author
]);
$this->assertEquals('author_id', $assoc->foreignKey());
$this->assertEquals('another_key', $assoc->foreignKey('another_key'));
$this->assertEquals('another_key', $assoc->foreignKey());
}

/**
* Test that foreignKey generation ignores database names in target table.
*
* @return void
*/
public function testForeignKeyIgnoreDatabaseName()
{
$this->author->table('schema.authors');
$assoc = new HasMany('Articles', [
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/ORM/Association/HasOneTest.php
Expand Up @@ -78,6 +78,21 @@ public function tearDown()
TableRegistry::clear();
}

/**
* Tests that foreignKey() returns the correct configured value
*
* @return void
*/
public function testForeignKey()
{
$assoc = new HasOne('Profiles', [
'sourceTable' => $this->user
]);
$this->assertEquals('user_id', $assoc->foreignKey());
$this->assertEquals('another_key', $assoc->foreignKey('another_key'));
$this->assertEquals('another_key', $assoc->foreignKey());
}

/**
* Tests that the association reports it can be joined
*
Expand Down

0 comments on commit 2200cda

Please sign in to comment.