Model::hasChanged() always return true if params is array and any field is changed.
I think if send array to model::hasChanged, this method should check that fields in this array has changed.
Something like this
public function hasChanged(var fieldName = null) -> boolean
{
var changedFields;
let changedFields = this->getChangedFields();
/**
* If a field was specified we only check it
*/
if typeof fieldName == "string" {
return in_array(fieldName, changedFields);
} elseif (typeof fieldName == "array") {
foreach (changedFields as field) {
if in_array(field, changedFields) {
return true;
}
}
return false;
}
return count(changedFields) > 0;
}
I don't like this, maybe someone would like to check if only one of parameter of array was changed?
https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep#L3824
Actually if array is provided nothing happens with it right now.
I would like to add argument strict, if false(by default?) it will do what you want, if true it will check all keys, like array_intersect.
Created some PR for this, let me know what you think.
This is what I needed. Thanks!
Fixed in the 3.2.x branch