-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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 binding with a primary key containing the table name doesn't work correctly #2789
Comments
- this solves error in livewire, when has a model in a public property - livewire issue livewire/livewire#2789
This is not a livewire bug, i created a pr to solves it on laravel |
The actual issue here is that you shouldn't define the table on the primary key. I don't know why you're doing that? |
There is no bug. Your primary key value is invalid. You must write: protected $primaryKey = 'id'; |
So if you want to join a table (from for example a (global) scope) and both tables have an id, what should you use then? Issue::find(1) Will cause issues because both tables have an id. I could write that more explicit with for example: Issue::firstWhere('issues.id', 1) But implicit route model binding won't work. That's why I added the table name to |
The first example should never clash with a global scope issue. Most likely you're applying joins in a global scope that you shouldn't be doing in the first place. That'll indeed cause the issues you're experiencing. |
Using multiple subselects on the same table for now, less efficient in comparison with a join but no conflicts. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description
I'm getting an error when Livewire is making requests with changes:
And when I look into this it's caused by the primary key on the model which includes the table name:
When I remove the scopes which require this as the joined tables also include an
id
column and remove this custom primary key it's working.Exact steps to reproduce
Create a model with the table name in the primary key, for example:
And use that model in a component:
And bind something to
$something
in the view:Now type something in the input.
Stripped-down, copy-pastable code snippets
Context
The text was updated successfully, but these errors were encountered: