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

fix: Entity can't handle column named attributes #5781

Closed

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Mar 7, 2022

Description
Fixes #5762
Supersede #5763

  • fix Entity can't handle column named attributes
  • add new setter method "_set + key" for a attribute

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Add _set*() method as a setter.
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Mar 7, 2022
@MGatner
Copy link
Member

MGatner commented Mar 13, 2022

I like this solution better, but let's wrap up the Issue conversation first. I think it is quite possible that someone is using $entity->attributes = $_POST not realizing the current behavior is "unintended".

Comment on lines +447 to +456
// If a "`_set` + $key" method exists, it is a setter.
if (method_exists($this, '_' . $method)) {
$this->{$method}($value);

return $this;
}

// If a "`set` + $key" method exists, it is also a setter.
// But setAttributes() is not a setter for this.
if ($key !== 'attributes' && method_exists($this, $method)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If a "`_set` + $key" method exists, it is a setter.
if (method_exists($this, '_' . $method)) {
$this->{$method}($value);
return $this;
}
// If a "`set` + $key" method exists, it is also a setter.
// But setAttributes() is not a setter for this.
if ($key !== 'attributes' && method_exists($this, $method)) {
// If a "`_set` + $key" method exists, it is a setter, or
// if a "`set` + $key" method exists, it is also a setter.
// But setAttributes() is not a setter for this.
if (method_exists($this, '_' . $method) || ($key !== 'attributes' && method_exists($this, $method))) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make code shorter,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I found a bug in my code.

Why do you like shorter code?

@kenjis kenjis marked this pull request as draft March 18, 2022 08:14
@MGatner
Copy link
Member

MGatner commented Mar 18, 2022

Maybe mark this one to revisit for version 5?

@kenjis kenjis added the next major version? Read this for a relevant v5 idea label Mar 18, 2022
@kenjis
Copy link
Member Author

kenjis commented Mar 18, 2022

@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Mar 18, 2022
@kenjis kenjis closed this Feb 1, 2023
@kenjis kenjis deleted the fix-entity-column-attributes-v2 branch February 11, 2023 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them next major version? Read this for a relevant v5 idea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Entity can't handle column named attributes
3 participants