Sql syntax error for Belongs to many relationship.
`SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select `id` from `classes` inner join `item_class` on `classes`.`id` = `item_class`.`class_model_id` where `item_class`.`item_id` is null)`
_I think the selection should be classes.id ._
classes with model App\ClassModel .items with model App\Items .item_class belongsToMany relationship after creating BREAD asClassesApp\ClassModelitem_classnameidFixed by editing resources/views/formfields/relationship.blade.php .
Changed $options->key to $options->table.'.'.$options->key in pluck function argument.
The resulting value :
$selected_values = isset($dataTypeContent) ? $dataTypeContent->belongsToMany($options->model, $options->pivot_table)->pluck($options->table.'.'.$options->key)->all() : array();
Is there any fix already for this issue on the latest update? I have tried to update to the latest version but this issue still persists. Why is this issue closed?
Yes, but it either hasn't been merged yet or has but hasn't been released yet (Not sure offhand, and I'm not at a computer to check). It'll be going in the next release
@gentra I just closed because there was no response. The cause and solution to the error is as stated.
@Martian2050 hmm well yeah, I cannot really use that solution since it means I need to modify the library's code inside the vendor folder. However, I'm using Elastic Beanstalk where the libraries code get regenerated on every deploy so it won't work for my case.
The only temporary solution I do now is by using a different primary-key name for the tables so it won't conflict each other.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
Fixed by editing
resources/views/formfields/relationship.blade.php.Changed
$options->keyto$options->table.'.'.$options->keyin pluck function argument.The resulting value :
$selected_values = isset($dataTypeContent) ? $dataTypeContent->belongsToMany($options->model, $options->pivot_table)->pluck($options->table.'.'.$options->key)->all() : array();