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

Model::replicate() contains laravel_through_key when loaded via HasManyThrough relationship #51097

Closed
levu42 opened this issue Apr 17, 2024 · 0 comments

Comments

@levu42
Copy link
Contributor

levu42 commented Apr 17, 2024

Laravel Version

11.4.0

PHP Version

8.3.6

Database Driver & Version

SQLite 3.45.3

Description

When a model is loaded through a HasManyThrough relation, it contains the laravel_through_key attribute. When I then use ->replicate() on that model, the replication also contains the laravel_through_key. This leads to me not being able to save the replication, unless I manually remove the laravel_through_key.

Steps To Reproduce

Here's a failing test in a reproducer repository:

    $organization = Organization::create();
    $department = Department::create(['organization_id' => $organization->id]);
    Employee::create(['department_id' => $department->id, 'name' => 'John']);

    $employee = $organization->employees()->first();

    $otherEmployee = $employee->replicate();
    $otherEmployee->name = 'Jane';
    $otherEmployee->save();

This gives the error message:

  SQLSTATE[HY000]: General error: 1 table employees has no column named laravel_through_key (Connection: sqlite, SQL: insert into "employees" ("name", "department_id", "laravel_through_key", "updated_at", "created_at") values (Jane, 1, 1, 2024-04-17 11:37:07, 2024-04-17 11:37:07))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant