Skip to content

Commit

Permalink
Fixes phalcon#12975, phalcon#13477: allowEmptyStrings & skipAttribute…
Browse files Browse the repository at this point in the history
…s adhere col map

allowEmptyStrings and skipAttributes will follow the column mapping from now on.
  • Loading branch information
CameronHall committed Dec 24, 2018
1 parent 80ced23 commit 7082427
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,4 @@

## Fixed
- Fixed `Phalcon\Mvc\Models` magic method (setter) is fixed for arrays [#13661](https://github.com/phalcon/cphalcon/issues/13661)
- Fixed `Phalcon\Mvc\Model::skipAttributes` and `Phalcon\Mvc\Model::allowEmptyColumns` allowEmptyStrings & skipAttributes repsect the column mapping. [#12975](https://github.com/phalcon/cphalcon/issues/12975), [#13477](https://github.com/phalcon/cphalcon/issues/13477)
64 changes: 33 additions & 31 deletions phalcon/mvc/model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3075,18 +3075,18 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
*/
for field in attributes {

if !isset automaticAttributes[field] {

/**
* Check if the model has a column map
*/
if typeof columnMap == "array" {
if !fetch attributeField, columnMap[field] {
throw new Exception("Column '" . field . "' isn't part of the column map");
}
} else {
let attributeField = field;
/**
* Check if the model has a column map
*/
if typeof columnMap == "array" {
if !fetch attributeField, columnMap[field] {
throw new Exception("Column '" . field . "' isn't part of the column map");
}
} else {
let attributeField = field;
}

if !isset automaticAttributes[attributeField] {

/**
* Check every attribute in the model except identity field
Expand Down Expand Up @@ -3274,7 +3274,7 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
}

let dataTypes = metaData->getDataTypes(this),
bindDataTypes = metaData->getBindTypes(this),
bindDataTypes = metaData->getBindTypes(this),
nonPrimary = metaData->getNonPrimaryKeyAttributes(this),
automaticAttributes = metaData->getAutomaticUpdateAttributes(this);

Expand All @@ -3289,7 +3289,18 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
*/
for field in nonPrimary {

if !isset automaticAttributes[field] {
/**
* Check if the model has a column map
*/
if typeof columnMap == "array" {
if !fetch attributeField, columnMap[field] {
throw new Exception("Column '" . field . "' isn't part of the column map");
}
} else {
let attributeField = field;
}

if !isset automaticAttributes[attributeField] {

/**
* Check a bind type for field to update
Expand All @@ -3298,16 +3309,6 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
throw new Exception("Column '" . field . "' have not defined a bind data type");
}

/**
* Check if the model has a column map
*/
if typeof columnMap == "array" {
if !fetch attributeField, columnMap[field] {
throw new Exception("Column '" . field . "' isn't part of the column map");
}
} else {
let attributeField = field;
}

/**
* Get the field's value
Expand Down Expand Up @@ -3939,20 +3940,21 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
let error = false;
for field in notNull {

if typeof columnMap == "array" {
if !fetch attributeField, columnMap[field] {
throw new Exception("Column '" . field . "' isn't part of the column map");
}
} else {
let attributeField = field;
}

/**
* We don't check fields that must be omitted
*/
if !isset automaticAttributes[field] {
if !isset automaticAttributes[attributeField] {

let isNull = false;

if typeof columnMap == "array" {
if !fetch attributeField, columnMap[field] {
throw new Exception("Column '" . field . "' isn't part of the column map");
}
} else {
let attributeField = field;
}

/**
* Field is null when: 1) is not set, 2) is numeric but
Expand Down

0 comments on commit 7082427

Please sign in to comment.