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

Filter by one argument with both field and callback #51

Closed
stefanozoffoli opened this issue Nov 25, 2015 · 3 comments
Closed

Filter by one argument with both field and callback #51

stefanozoffoli opened this issue Nov 25, 2015 · 3 comments

Comments

@stefanozoffoli
Copy link

Hi,

I have a table with this searchConfiguration:

    public function searchConfiguration() {
        $search = new Manager($this);

        $search
            ->like('q', [
                'before' => true,
                'after' => true,
                'field' => [
                    $this->aliasField('code'),
                    $this->aliasField('company_name'),
                    $this->aliasField('first_name'),
                    $this->aliasField('last_name'),
                ],
            ])
            ->callback('q', [
                'callback' => function ($query, $args, $manager) {
                    $query
                        ->orWhere([
                            'Clients.id IN' => $this->Contacts->find('search', $this->Contacts->filterParams($args))
                                ->select([
                                    'Contacts.foreign_id',
                                ]),
                        ]);
                }
            ]);

        return $search;
    }

The second filter callback('q') overwrites the first filter like('q').
Is it possible to have both working at the same time?

@burzum
Copy link
Contributor

burzum commented Dec 16, 2015

I don't think so, AFAIK they don't stack. I like the idea but now sure how easy and quick it can be done. As a workaround you could simply just do your own LIKE query inside your callback()'s query.

@dereuromark
Copy link
Member

Can we have a test here to proof this is currently working or not working as expected?
Then we can figure out how to solve it.

@dereuromark
Copy link
Member

Yeah, a custom one is needed here (or different keys) as the key is the one deciding which filter will be used, so must be unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants