Skip to content

Bug: Unnecessary foreign key for Entity::$original #19

Description

@neznaika0

Describe the bug
It seems we have an extra field/property after the query. The Entity::$original contains a foreign key: post_id, user_id..
In Relation::filterResults() Relation::filterResult(), we delete it, but there is no synchronization, unset from $attributes only.

$this->model
->select(
sprintf(
'%s.*, %s.%s',
$this->model->getTable(),
$this->many->pivotTable,
$this->many->pivotForeignKey,
),
)

To Reproduce
Output debug object:

    protected attributes -> array (5) [
        'id' => string (1) "1"
        'name' => string (18) "Baking for dummies"
        'total_hours' => string (2) "30"
        'created_at' => string (19) "2025-10-06 18:55:21"
        'updated_at' => string (19) "2025-10-06 18:55:21"
    ]
    protected original -> array (6) [
        'id' => string (1) "1"
        'name' => string (18) "Baking for dummies"
        'total_hours' => string (2) "30"
        'created_at' => string (19) "2025-10-06 18:55:21"
        'updated_at' => string (19) "2025-10-06 18:55:21"
        'student_id' => string (1) "1" // <<<
    ]

Expected behavior
Unnecessary properties are not needed.

Screenshots
No.

Environment (please complete the following information):

  • PHP: PHP 8.4.13
  • Version: dev-latest
  • CodeIgniter: 4.6.3

Additional context
I tried to add synchronization to the right places, but it looks terrible. Maybe you know a better solution.
See also HasRelations::getDataForRelationByIds(), HasRelations::getDataForRelationById().
You can add array processing at the end of return $row->syncOriginal()

I think the object should be 100% synchronized after all the manipulations, because new values are being added.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions