Skip to content

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

Closed
kenjis wants to merge 1 commit into
codeigniter4:developfrom
kenjis:fix-entity-column-attributes-v2
Closed

kenjis wants to merge 1 commit into
codeigniter4:developfrom
kenjis:fix-entity-column-attributes-v2

Conversation

@kenjis

@kenjis kenjis commented Mar 7, 2022

Copy link
Copy Markdown
Member

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

MGatner commented Mar 13, 2022

Copy link
Copy Markdown
Member

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 thread system/Entity/Entity.php
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

MGatner commented Mar 18, 2022

Copy link
Copy Markdown
Member

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

kenjis commented Mar 18, 2022

Copy link
Copy Markdown
Member Author

@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