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

support subqueries as where values #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

midnightmonster
Copy link

Supports queries like this, which can be expressed as joins but are often easier to understand expressed this way--and faster to execute in MySQL:

$rentals = $h->table('rental_properties');
$favorites = $h->table('user_favorite_rental_properties');
$rentals->select()->where('id', 'in',
    $favorites->
        select(['rental_property_id'])->
        where('user_id',$_SESSION['user_id'])
)->where('available', true);

becomes

select * from `rental_properties` where `id` in (select `rental_property_id` from `user_favorite_rental_properties` where `user_id` = ?) and `available` = ?
[12345, true]

I'm on a deadline at the moment but will come back later this week to add some tests if you want them and approve this general approach.

@radar3301
Copy link

Line 546: elseif (is_object($where[3]) && ($where[3] instanceof BaseQuery))

should be: elseif (is_object($where[3]) && ($where[3] instanceof SelectBase))

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

Successfully merging this pull request may close these issues.

2 participants