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

Adding a HasMany relation correctly #257

Closed
Norgul opened this issue Jul 4, 2024 · 2 comments
Closed

Adding a HasMany relation correctly #257

Norgul opened this issue Jul 4, 2024 · 2 comments

Comments

@Norgul
Copy link

Norgul commented Jul 4, 2024

I have a parent_id on my model table so I have used that to create parent/child relations:

public function parent(): BelongsTo
{
    return $this->belongsTo(self::class, 'parent_id');
}

public function children(): HasMany
{
    return $this->hasMany(self::class, 'parent_id');
}

Relations work just fine (tried and tested in Tinker).

I have tried using it like this:

Multiselect::make('Children', 'children')
    ->options(\App\Models\Tenant\Unit::all()->pluck('label', 'id'))
    ->taggable(false),

And I can pick & choose units from the list, however when I want to save it says

Column not found: 1054 Unknown column 'children' in 'field list'

@KasparRosin
Copy link
Member

Multiselect currently does not support HasMany relationship, only belongsTo and belongsToMany.
There is sadly no way at the moment to add HasMany via Multiselect.

@Norgul
Copy link
Author

Norgul commented Jul 16, 2024

Just wanted to add that in the mean time I have hacked it to work with fillUsing(), but reverted all of that as it makes no sense.

Reason it makes no sense is because it is essentially re-parenting children, changing their parent_id which might already be set. I would close this issue sooner would I not have forgotten I submitted it.

I would support the decision to never implement this.

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

2 participants