Skip to content

Commit

Permalink
Segfault fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Németh Balázs committed May 11, 2019
1 parent 45d8d90 commit 85f53a1
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
*/
public function __set(string property, value)
{
var lowerProperty, related, modelName, manager, lowerKey, relation,
referencedModel, key, item, dirtyState;
var lowerProperty, related, modelName, manager,
relation, referencedModel, item, dirtyState;

/**
* Values are probably relationships if they are objects
Expand Down Expand Up @@ -2270,8 +2270,8 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
*/
public function save() -> bool
{
var metaData, schema, writeConnection, readConnection, source,
table, identityField, exists, success, relatedUnsaved;
var metaData, schema, writeConnection, readConnection, source, table,
identityField, exists, success, related, relatedSaved, relatedUnsaved;
bool hasRelatedUnsaved;

let metaData = this->getModelsMetaData();
Expand All @@ -2286,16 +2286,21 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
*/
this->fireEvent("prepareSave");

/**
* Load related storages
*/
let related = this->related,
relatedUnsaved = this->relatedUnsaved;

/**
* Store the original records as a base for the updated ones
*/
let this->relatedSaved = this->related;
let this->relatedSaved = related;

/**
* Save related records in belongsTo relationships
* Does it have unsaved related records
*/
let relatedUnsaved = this->relatedUnsaved,
hasRelatedUnsaved = count(relatedUnsaved) > 0;
let hasRelatedUnsaved = count(relatedUnsaved) > 0;

if hasRelatedUnsaved {
if this->_preSaveRelatedRecords(writeConnection, relatedUnsaved) === false {
Expand Down Expand Up @@ -2415,10 +2420,12 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
this->_cancelOperation();
} else {
if hasRelatedUnsaved {
let relatedSaved = this->relatedSaved;

/**
* Update and clear related caches
*/
let this->related = this->relatedSaved,
let this->related = relatedSaved,
this->relatedUnsaved = [],
this->relatedSaved = [];
}
Expand Down

0 comments on commit 85f53a1

Please sign in to comment.