Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Active Record Where #29

Open
patrickheeney opened this issue Sep 27, 2013 · 1 comment
Open

Active Record Where #29

patrickheeney opened this issue Sep 27, 2013 · 1 comment

Comments

@patrickheeney
Copy link

The ActiveRecord $model->or_where() only really works when you have a table where field = value or field = value2. For example if you do $model->where()->where()->or_where() it actually creates the sql as table where (field = value) and (field = value2) or (field = value3) which doesn't work as you would expect it.

Ideally we could pass a closure into where to solve this or at least create some sort of grouping to that the or_where can be applied in the right place with the right grouping.

Code from another framework:

DB::table('users')
            ->where('name', '=', 'John')
            ->orWhere(function($query)
            {
                $query->where('votes', '>', 100)
                      ->where('title', '<>', 'Admin');
            })
            ->get();

Will produce:

select * from users where name = 'John' or (votes > 100 and title <> 'Admin')
@EHLOVader
Copy link

What about tree management through group open and close commands?

methods like openParen|closeParen, or maybe just or|and paired with ro|dna to close them?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants