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

Comments

Projects
None yet
3 participants
@mzf

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

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Mar 1, 2017

Member

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.

Member

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 Jurigag referenced this issue Mar 15, 2017

Merged

3.2.x Model hasChanged array #12713

3 of 3 tasks complete
@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Mar 15, 2017

Member

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

Member

Jurigag commented Mar 15, 2017

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

@mzf

This comment has been minimized.

Show comment
Hide comment
@mzf

mzf Mar 15, 2017

This is what I needed. Thanks!

mzf commented Mar 15, 2017

This is what I needed. Thanks!

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

@sergeyklay

This comment has been minimized.

Show comment
Hide comment
@sergeyklay

sergeyklay May 8, 2017

Member

Fixed in the 3.2.x branch

Member

sergeyklay commented May 8, 2017

Fixed in the 3.2.x branch

@sergeyklay sergeyklay closed this May 8, 2017

@sergeyklay sergeyklay added the Bug - Low label May 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment