Closed klaaskox closed 3 months ago
Hello there! Thanks for opening your first issue on this repo!
Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.
Backpack communication channels:
backpack-for-laravel
tag;Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.
Thank you!
-- Justin Case The Backpack Robot
Problem solved by changing the relationships:
public function includedKeyvalues(): BelongsToMany
{
return $this->belongsToMany(Keyvalue::class, 'keyvalue_links', 'question_id', 'keyvalue_id')
->withPivotValue('type', 'include');
}
public function excludedKeyvalues(): BelongsToMany
{
return $this->belongsToMany(Keyvalue::class, 'keyvalue_links', 'question_id', 'keyvalue_id')
->withPivotValue('type', 'exclude');
}
Bug report
What I did
I have two models:
Question
andAnswer
. These models have n-n relationships with another model namedKeyvalue
. These relationships have an attributetype
which can be "include" or "exclude".I am using one pivot table "keyvalue_links" with these columns:
I defined the relationship in the
Question
model as follows:I am using
select2_multiple
fields in my CrudController:What I expected to happen
When editing a question, the included and excluded keyvalues should be loaded correctly, and when updating these values, they should be stored correctly in the database.
What happened
The data is loaded correctly, but when I save/update the model, the type attribute isn't set correctly. It is always set to "include" (which is the default value).
What I've already tried to fix it
I monitored the database queries and found out that the type attribute isn't set, so the database sets it to the default value ("include")
Is it a bug in the latest version of Backpack?
After I run
composer update backpack/crud
the bug... is it still there? YesBackpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is: