Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed saving a model after fetching its related records #13985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
- Fixed `Mvc\Model::save()` throwing an exception after fetching its related records (many/many-to-many) via `__get()` [#13985](https://github.com/phalcon/cphalcon/pull/13985)

## Removed
- Removed `arrayHelpers` property from the Volt compiler. [#13925](https://github.com/phalcon/cphalcon/pull/13925)
Expand Down
5 changes: 4 additions & 1 deletion phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface

/**
* We store relationship objects in the related bag
*
* Removed temporarily.
* See https://github.com/phalcon/cphalcon/issues/13964
*/
let this->related[lowerProperty] = result;
// let this->related[lowerProperty] = result;
}

return result;
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/Mvc/Model/Refactor-ModelsRelationsMagicCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testModelsMysql(IntegrationTester $I)
$this->setDiMysql();

$this->executeQueryRelated($I);
$this->executeSaveAfterQueryRelated($I);
$this->executeSaveRelatedBelongsTo($I);
}

Expand Down Expand Up @@ -54,6 +55,12 @@ public function testModelsSqlite()
$this->_executeSaveRelatedBelongsTo($connection);
}*/

/**
* Test for issue: #13964
* See: https://github.com/phalcon/cphalcon/issues/13964
*
* @param IntegrationTester $I
*/
private function executeQueryRelated(IntegrationTester $I)
{

Expand All @@ -78,6 +85,22 @@ private function executeQueryRelated(IntegrationTester $I)
$I->assertEquals($originalAlbum->id, $album->id);
}

private function executeSaveAfterQueryRelated(IntegrationTester $I)
{
$album = Albums::findFirst();
$artist = $album->artist;

$I->assertTrue($album->save());

$artist->albums;

$I->assertTrue($artist->save());

$album->songs;

$I->assertTrue($album->save());
}

private function executeSaveRelatedBelongsTo(IntegrationTester $I)
{
$connection = $this->getService('db');
Expand Down