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

Searchable with join #1592

Open
Epitaffio opened this issue Jun 13, 2024 · 0 comments
Open

Searchable with join #1592

Epitaffio opened this issue Jun 13, 2024 · 0 comments

Comments

@Epitaffio
Copy link

Epitaffio commented Jun 13, 2024

Have you searched through other issues to see if your problem is already reported or has been fixed?

Yes, I did not find it.

Did you read the documentation?

Yes, I did not find it.

Have you tried to publish the views?

No, this error is not related to views.

Is there an error in the console?

No

PHP Version

8.3

PowerGrid

5.8.0

Laravel

11.10

Livewire

3.5.0

Alpine JS

No response

Theme

Tailwind 3.x

Describe the bug.

Hi, I am struggling to find why my implementation doesn't work.

For background II have 2 table that I have joined in the datasource (for the sake of testing I have added all the possible variations for my field):

    public function datasource(): Builder
    {
        return Cliente::query()
            ->select('clienti.*', 'agenti.AGDESAGE', 'agenti.AGDESAGE as agenti_desc', 'agenti.AGDESAGE as AGDESAGE')
            ->leftJoin('agenti', 'agenti.id',  'clienti.agente_id');
    }

In the fileds definition I have added all the variants:

    public function fields(): PowerGridFields
    {
        return PowerGrid::fields()
            ->add('agenti.AGDESAGE')
            ->add('AGDESAGE')
            ->add('agenti_desc');
    }

As also in the columns method:

public function columns(): array
    {
        return [
            Column::make('Codice', 'ANCODICE')->sortable()->searchable(),

            Column::make('test0', 'agenti_desc')->searchable()->sortable(),
            Column::make('test1', 'agenti_desc', 'agenti.AGDESAGE')->searchable()->sortable(),
            Column::make('test2', 'agenti_desc', 'AGDESAGE')->searchable()->sortable(),
            Column::make('test3', 'agenti.AGDESAGE')->searchable()->sortable(),
            Column::make('test4', 'AGDESAGE')->searchable()->sortable(),
        ];
    }

The sql is generated correctly and I can order all the fields

select `clienti`.*, `agenti`.`AGDESAGE`, `agenti`.`AGDESAGE` as `agenti_desc`, `agenti`.`AGDESAGE` as `AGDESAGE` from `clienti` inner join `agenti` on `agenti`.`id` = `clienti`.`agente_id` order by `ANCODICE` asc limit 10 offset 0

but when I try to use the global search, the joined field are ignored:

select count(*) as aggregate from `clienti` inner join `agenti` on `agenti`.`id` = `clienti`.`agente_id` where ((`clienti`.`ANCODICE` LIKE '%aaaa%'))

I can't understand what I am doing different from the join example in the docs (https://demo.livewire-powergrid.com/examples/datasource-join).

Digging in the package code the only place where I can see maybe(?) an error is inside src/DataSource/Builder.php

on line 141

$columnList = $this->getColumnList($modelTable);

Where the method return the original table's field list but not the joined ones, so the consequential on line 152 gave false and the column is skipped

$hasColumn = isset($columnList[$field]);

But why in the join demo it works?

Hope someone can point me in the right direction, thanks!

To Reproduce...

No response

Extra information

No response

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

1 participant