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

dirtyAttributes #622

Closed
lancecoder opened this issue Jul 14, 2013 · 6 comments
Closed

dirtyAttributes #622

lancecoder opened this issue Jul 14, 2013 · 6 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@lancecoder
Copy link
Contributor

https://github.com/yiisoft/yii2/blob/master/framework/yii/db/ActiveRecord.php#L597
if isset attr1 and attr2 and changed attr1 than ->isAttributeChanged('attr2') return true

@lancecoder
Copy link
Contributor Author

model have 2 attributes - id and name
check way:
$model->setOldAttribute('id', 2);
$model->isAttributeChanges('name');
//bad rule -> || isset($this->_oldAttributes)

@lancecoder
Copy link
Contributor Author

Возможно написано плохо, с письменным английским не очень, переведите кто может, если вдруг по вышенаписанному невозможно понять суть
Имея модель, к примеру User, в которой 2 аттрибута (колонки/столбца) изменить 1, а запросить на изменение другой, то вернет тру
т.к. правиило iisset($this->_attributes[$name], $this->_oldAttributes[$name]) вернет фальш, ибо не будет его в измененных
а правило isset($this->_attributes[$name]) || isset($this->_oldAttributes) вернет тру или тру, т.к. старые аттрибуты уже не будет нулл

@qiangxue
Copy link
Member

Thanks!

cebe added a commit to cebe/yii2 that referenced this issue Aug 26, 2013
* 'master' of github.com:yiisoft/yii2:
  Asset feature refactoring (WIP)
  Fixes yiisoft#622.
  Fixed matching all case.
@makroxyz
Copy link
Contributor

public function isAttributeChanged($name)
{
    if (isset($this->_attributes[$name], $this->_oldAttributes[$name])) {
        return $this->_attributes[$name] !== $this->_oldAttributes[$name]; // ***
    } else {
        return isset($this->_attributes[$name]) || isset($this->_oldAttributes[$name]);
    }
}

*** after form POST all attributes become strings... an integer value becomes "1" so the operator !== returns true even if attribute has the same value

@cebe
Copy link
Member

cebe commented Dec 12, 2013

Can you please open a new issue for this?

@makroxyz
Copy link
Contributor

sure!

2013/12/12 Carsten Brandt notifications@github.com

Can you please open a new issue for this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/622#issuecomment-30461949
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

4 participants