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

Model::hasChanged($params) always return true if $params is array and any field is changed #12669

Closed
mzf opened this issue Mar 1, 2017 · 4 comments
Labels
bug A bug report status: low Low
Milestone

Comments

@mzf
Copy link

mzf commented Mar 1, 2017

Expected and Actual Behavior

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;
	}
  • Phalcon version: 3.0.4
  • PHP Version: 7.0.15
  • Operating System: Win7
@Jurigag
Copy link
Contributor

Jurigag commented Mar 1, 2017

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.

@Jurigag
Copy link
Contributor

Jurigag commented Mar 15, 2017

Created some PR for this, let me know what you think.

@mzf
Copy link
Author

mzf commented Mar 15, 2017

This is what I needed. Thanks!

@sergeyklay sergeyklay added this to the unplanned milestone May 8, 2017
@sergeyklay
Copy link
Contributor

Fixed in the 3.2.x branch

@niden niden added bug A bug report status: low Low and removed Bug - Low labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
None yet
Development

No branches or pull requests

4 participants