-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12068 from CrNix/3.0.x-vkey-fix
Fixed virtual foreign key check
- Loading branch information
Showing
7 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Models\BodyParts; | ||
|
||
use Phalcon\Mvc\Model; | ||
|
||
/** | ||
* \Phalcon\Test\Models\Body | ||
* | ||
* @copyright (c) 2011-2016 Phalcon Team | ||
* @link http://www.phalconphp.com | ||
* @author Radek Crlík <[email protected]> | ||
* @package Phalcon\Test\Models\BodyParts | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to [email protected] | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class Body extends Model | ||
{ | ||
|
||
public $id; | ||
public $head_1_id; | ||
public $head_2_id; | ||
|
||
public function initialize() | ||
{ | ||
$this->setSource('issue12071_body'); | ||
|
||
$this->belongsTo( | ||
'head_1_id', | ||
'\Phalcon\Test\Models\BodyParts\Head', | ||
'id', | ||
[ | ||
'alias' => 'head1', | ||
"foreignKey" => [ | ||
"allowNulls" => true, | ||
"message" => "First head does not exists" | ||
] | ||
] | ||
); | ||
|
||
$this->belongsTo( | ||
'head_2_id', | ||
'\Phalcon\Test\Models\BodyParts\Head', | ||
'id', | ||
[ | ||
'alias' => 'head2', | ||
"foreignKey" => [ | ||
"allowNulls" => true, | ||
"message" => "Second head does not exists" | ||
] | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Models\BodyParts; | ||
|
||
use Phalcon\Mvc\Model; | ||
|
||
/** | ||
* \Phalcon\Test\Models\Head | ||
* | ||
* @copyright (c) 2011-2016 Phalcon Team | ||
* @link http://www.phalconphp.com | ||
* @author Radek Crlík <[email protected]> | ||
* @package Phalcon\Test\Models\BodyParts | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to [email protected] | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class Head extends Model | ||
{ | ||
|
||
public $id; | ||
|
||
public function initialize() | ||
{ | ||
$this->setSource('issue12071_head'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use Phalcon\Test\Models\PackageDetails; | ||
use Phalcon\Mvc\Model\Resultset\Simple; | ||
use Phalcon\Test\Models\AlbumORama\Albums; | ||
use Phalcon\Test\Models\BodyParts\Body; | ||
|
||
/** | ||
* \Phalcon\Test\Unit\Mvc\Model\ManagerTest | ||
|
@@ -157,4 +158,33 @@ function () { | |
} | ||
); | ||
} | ||
|
||
/** | ||
* Tests virtual foreign keys. | ||
* | ||
* When having multiple virtual foreign keys, check of the first one should | ||
* affect the check of the next one. | ||
* | ||
* @issue 12071 | ||
* @author Radek Crlik <[email protected]> | ||
* @since 2016-08-03 | ||
*/ | ||
public function testInvalidVirtualForeignKeys() | ||
{ | ||
$this->specify( | ||
'The Model::save with multiple virtual foreign keys and invalid entity', | ||
function () { | ||
$body = new Body(); | ||
|
||
$body->head_1_id = null; | ||
$body->head_2_id = 999; | ||
|
||
// PDOException should'n be thrown | ||
expect($body->save())->equals(false); | ||
|
||
expect($body->getMessages())->count(1); | ||
expect($body->getMessages()[0]->getMessage())->equals('Second head does not exists'); | ||
} | ||
); | ||
} | ||
} |