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
Unable to check if ActiveRecord own properties isset or empty using array access notation #17717
Comments
BaseActiveRecord extends yii\base\Model which implements the suggestion above. We can remove offsetExists method from the BaseActiveRecord class and rely on the Model classes implementation. yii\base\Model::offsetExists public function offsetExists($offset)
{
return isset($this->$offset);
} |
Potentially that may break things. @yiisoft/core-developers, @yiisoft/reviewers what do you think? Any breaks that may happen? |
If you need to check properties, please check from The fact that ActiveRecord "hides" this exception is very frustrating. |
Since recent versions yii starts to check isset on attribute when loading relations in \yii\db\ActiveRelationTrait::filterByModels
Until recent versions, relations of this kind worked
Now they don't . \yii\db\BaseActiveRecord::offsetUnset() method checks for the existence of the property:
Maybe just add the same check to \yii\db\BaseActiveRecord::offsetExists() method?
|
@samdark Was this issue sorted or how do we debunk this problem? |
The original one descibed in the initla post? No. In order to solve it, a pull request would be great to see if it breaks any existing tests. |
What steps will reproduce the problem?
Created a ActiveRecord model class, for example:
And run code like this:
What is the expected result?
What do you get instead?
Suggestion:
Change implementation of BaseActiveRecor::offsetExists from:
to:
So it will cover own ActiveRecord properties and fallback to __isset when needed.
Additional info
The text was updated successfully, but these errors were encountered: