Skip to content

Commit

Permalink
Merge pull request #14003 from SidRoberts/model-relation-isforeignkey
Browse files Browse the repository at this point in the history
Model\Relation::isForeignKey() now returns false if the option is false
  • Loading branch information
sergeyklay authored Apr 18, 2019
2 parents 77ef143 + 08a05ce commit 85a60f2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Query Builder's `GROUP BY` field is now always an array. [#13962](https://github.com/phalcon/cphalcon/pull/13962)
- Renamed `Phalcon\Paginator\Adapter::getPaginate()` to `paginate()` in documentation/tests (originally renamed in 4.0.0-alpha.1). [#13973](https://github.com/phalcon/cphalcon/pull/13973)
- Fixed the exception message in `Phalcon\Security::computeHmac()` by removing `"%s"` from output.
- `Phalcon\Mvc\Model\Relation::isForeignKey()` now returns false if the `foreignKey` option is set to `false`.

## Removed
- Removed `arrayHelpers` property from the Volt compiler. [#13925](https://github.com/phalcon/cphalcon/pull/13925)
Expand Down
8 changes: 7 additions & 1 deletion phalcon/Mvc/Model/Relation.zep
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ class Relation implements RelationInterface
*/
public function isForeignKey() -> bool
{
return isset this->options["foreignKey"];
var foreignKey;

if !fetch foreignKey, this->options["foreignKey"] {
return false;
}

return (bool) foreignKey;
}

/**
Expand Down
96 changes: 93 additions & 3 deletions tests/integration/Mvc/Model/Relation/IsForeignKeyCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Phalcon\Test\Integration\Mvc\Model\Relation;

use IntegrationTester;
use Phalcon\Mvc\Model\Relation;

/**
* Class IsForeignKeyCest
Expand All @@ -24,12 +25,101 @@ class IsForeignKeyCest
*
* @param IntegrationTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2018-11-13
* @author Sid Roberts <[email protected]>
* @since 2019-04-18
*/
public function mvcModelRelationIsForeignKey(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model\Relation - isForeignKey()');
$I->skipTest('Need implementation');



$options = [];

$relation = new Relation(
Relation::HAS_MANY,
'RobotsParts',
'id',
'robots_id',
$options
);

$I->assertFalse(
$relation->isForeignKey()
);



$options = [
'foreignKey' => false,
];

$relation = new Relation(
Relation::HAS_MANY,
'RobotsParts',
'id',
'robots_id',
$options
);

$I->assertFalse(
$relation->isForeignKey()
);



$options = [
'foreignKey' => [],
];

$relation = new Relation(
Relation::HAS_MANY,
'RobotsParts',
'id',
'robots_id',
$options
);

$I->assertFalse(
$relation->isForeignKey()
);



$options = [
'foreignKey' => true,
];

$relation = new Relation(
Relation::HAS_MANY,
'RobotsParts',
'id',
'robots_id',
$options
);

$I->assertTrue(
$relation->isForeignKey()
);



$options = [
'foreignKey' => [
'message' => 'The part_id does not exist on the Parts model',
],
];

$relation = new Relation(
Relation::HAS_MANY,
'RobotsParts',
'id',
'robots_id',
$options
);

$I->assertTrue(
$relation->isForeignKey()
);
}
}

0 comments on commit 85a60f2

Please sign in to comment.