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

[BUG]: Model->toArray not checking/using getters #16320

Closed
noone-silent opened this issue Apr 10, 2023 · 1 comment
Closed

[BUG]: Model->toArray not checking/using getters #16320

noone-silent opened this issue Apr 10, 2023 · 1 comment
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@noone-silent
Copy link
Contributor

Questions? Forum: https://phalcon.io/forum or Discord: https://phalcon.io/discord

Describe the bug
toArray uses the value directly instead using getters if exists. If a getter for a field exists, it should always be used.

To Reproduce
See linked line in code

Steps to reproduce the behavior:

CREATE TABLE test_table (
    id SERIAL,
    db_field VARCHAR(50) NULL
);

INSERT INTO test_table VALUES (1, 'test value');

class TestModel extends \Phalcon\Mvc\Model
{

    /**
     * @Primary
     * @Identity
     * @Column(type="integer", nullable=false, column="id")
     */
    private ?int $id = null;

    /**
     * @Column(type="string", nullable=true, column="db_field")
     */
    private ?string $dbField = null;

    public function initialize(): void
    {
        $this->setSource('test_table');
    }

    public function getDbField(): string
    {
        return 'Some Prefix: ' . ($this->dbField ?? '');
    }
}

$test = TestModel::findFirst(1);
var_dump($test->toArray()); 
// array(2) {
//  ["id"]=> int(1)
//  ["dbField"]=>  string(10) "test value"
// }

Expected behavior
toArray should call the getters.

// Expected output from script above

echo $test->toArray();
// array(2) {
//  ["id"]=> int(1)
//  ["dbField"]=>  string(23) "Some prefix: test value"
// }

Details

  • Phalcon version: v4 and v5
  • PHP Version: 8.1.2
  • Operating System: debian
  • Installation type: installing via package manager
  • Zephir version (if any):
  • Server: Nginx
  • Other related info (Database, table schema): Mariadb
@noone-silent noone-silent added bug A bug report status: unverified Unverified labels Apr 10, 2023
@niden niden added this to Phalcon v5 Jul 31, 2023
@niden niden moved this to Backlog in Phalcon v5 Jul 31, 2023
@niden niden self-assigned this Nov 24, 2023
@niden niden moved this from Backlog to In Progress in Phalcon v5 Nov 24, 2023
@niden niden added status: medium Medium 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Nov 24, 2023
@niden niden moved this from In Progress to Implemented in Phalcon v5 Nov 24, 2023
@niden
Copy link
Member

niden commented Nov 24, 2023

Resolved in #16469

Thank you @noone-silent

@niden niden closed this as completed Nov 24, 2023
@niden niden moved this from Implemented to Released in Phalcon v5 Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: Released
Development

No branches or pull requests

2 participants