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

[Bug]: Builder does not support BelongsToMany #2176

Open
mbrioski opened this issue Jan 15, 2025 · 1 comment
Open

[Bug]: Builder does not support BelongsToMany #2176

mbrioski opened this issue Jan 15, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@mbrioski
Copy link

mbrioski commented Jan 15, 2025

What happened?

It seems that the relation of type BelongsToMany is not supported in the builder method:
public function builder(): Builder

In fact, debugging the code i can see in Rappasoft\LaravelLivewireTables\Traits\WithData

protected function getTableForColumn(Column $column): ?string
    {
        $table = null;
        $lastQuery = clone $this->getBuilder();

        foreach ($column->getRelations() as $relationPart) {
            $model = $lastQuery->getRelation($relationPart);

            if ($model instanceof HasOne || $model instanceof BelongsTo || $model instanceof MorphOne) {
                $table = $this->getTableAlias($table, $relationPart);
            }

            $lastQuery = $model->getQuery();
        }

        return $table;
    }

It seems that if i have a BelongsToMany relation, what i get is the data of the model of the query

How to reproduce the bug

No response

Package Version

^3.5

PHP Version

8.3
None

Laravel Version

v11.12.0
No response

Alpine Version

No response

Theme

None

Notes

No response

Error Message

Rappasoft\LaravelLivewireTables\Views\Column::setTable(): Argument #1 ($table) must be of type string, null given, called in /var/www/html/portal/vendor/rappasoft/laravel-livewire-tables/src/Traits/Helpers/ColumnHelpers.php on line 43

@mbrioski mbrioski added the bug Something isn't working label Jan 15, 2025
@lrljoe
Copy link
Collaborator

lrljoe commented Jan 16, 2025

What're you trying to do in terms of the BelongsToMany relation?

Are you trying to display a list of the "BelongsToMany" related items?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants