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

Multiple conditional joins #172

Open
scott-wmm opened this issue Sep 14, 2017 · 2 comments
Open

Multiple conditional joins #172

scott-wmm opened this issue Sep 14, 2017 · 2 comments
Assignees

Comments

@scott-wmm
Copy link

scott-wmm commented Sep 14, 2017

Hey,

I need the ability to do multiple joins with a conditional 'AND' on each one.

For example the current query builder reads:

            $products
                ->join('product_to_categories', 'products.id', '=', 'product_to_categories.product')
                ->where(function($query) use($categories) {
                    foreach($categories as $category) {
                        $query->orWhere('product_to_categories.category', $category);
                    }
                });

However this returns all results that match all the given categories. I need to be able to only return the results that match both. Changing the 'orWhere' to simply 'where' returns no results as the singular JOIN can't match multiple conditions.

The raw query I'm looking for is roughly:

JOIN product_to_categories AS ptoc1
ON ptoc1.product =products.id AND (ptoc1.category_id='4')
JOIN product_to_categories AS ptoc2
ON ptoc2.product =products.id AND (ptoc2.category_id='5')

I've spent a few hours experimenting, can this be achieved using Pixie?

Thank you.

@usmanhalalit
Copy link
Owner

@TCB13 can you please check the issue?

@TCB13 TCB13 self-assigned this Dec 13, 2017
@TCB13
Copy link

TCB13 commented Dec 13, 2017

@scott-wmm I might be getting the wrong ideia on this, can you provide us with a dump of a a test database / data where I can do some tests?

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

3 participants