Skip to content

Active Record Where #29

Description

@patrickheeney

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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions