timgws / QueryBuilderParser

A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
MIT License
159 stars 65 forks source link

Filtering though multiple joins #25

Closed T0miii closed 6 years ago

T0miii commented 6 years ago

Hi,

dont know if you are still supporing this project, but i would like to have a question. I made an implementation of your filter in my laravel project. Working fine. Also could make the Join filtering work.

So if i want to get all my contracts with a partner located in a specific country i can just go:

protected $joins = [
        'country_id' =>  [
            'from_table'      => 'contract',
            'from_col'        => 'partner_id',
            'to_table'        => 'partner',
            'to_col'          => 'partner_id',
            'to_value_column' => 'country_id'
        ]
];

and i can get all contracts where partner got a country_id of 22 for example.

Now my question is how would you go about a fied that goes over multiple tables.

contract->partner->partner_service->service_charge

i need now all contracts with a charge of "50".

Would this be possible or is it a new feature?

timgws commented 6 years ago

Thanks for your email.

The filtering on joins should work. You just need to add multiple items to the join array.

---- On Tue, 16 Jan 2018 19:46:52 +1100 notifications@github.com wrote ----

Hi,

dont know if you are still supporing this project, but i would like to have a question. I made an implementation of your filter in my laravel project. Working fine. Also could make the Join filtering work.

So if i want to get all my contracts with a partner located in a specific country i can just go:

protected $joins = [ 'country_id' => [ 'from_table' => 'contract', 'from_col' => 'partner_id', 'to_table' => 'partner', 'to_col' => 'partner_id', 'to_value_column' => 'country_id' ] ]; and i can get all contracts where partner got a country_id of 22 for example.

Now my question is how would you go about a fied that goes over multiple tables.

contract->partner->partner_service->service_charge

i need now all contracts with a charge of "50".

Would this be possible or is it a new feature?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

T0miii commented 6 years ago

thx for the library and your fast response.

What im not sure about is how do i build my normal joins as an array required by the filter. Normaly i would go something like this:

select * from contract c join partner p ON p.partner_id = c-partner_id join service_partner sp ON sp.partner_id = p.partner_id join service_charge sch ON sch.service_id = sp.service_id.

and then i would just add a where to get the filter for the price:

where sch.price = 80

Not quit sure how i could do this with the filter cause its based on exists, its might not even possible.

timgws commented 6 years ago

Not quit sure how i could do this with the filter cause its based on exists, its might not even possible.

Can you paste what your query is before it is passed to the QueryBuilder (ie, dd($query->toSql()))

timgws commented 6 years ago

Closing due to non-response.