active-record icon indicating copy to clipboard operation
active-record copied to clipboard

Active Record 'OR' query

Open senguttuvang opened this issue 7 years ago • 2 comments

This is a feature request, not a bug. Currently, AR does only AND across Active Query methods. What if we would like to OR, NOT among those methods?

Let me explain with an example.

Lesson::find()->scheduled()->all();// fetch all scheduled lessons Lesson::find()->completed()->all();// fetch all accepted lessons Lesson::find()->canceled()->all();// fetch all canceled lessons

I'd like to do something like this to fetch scheduled or completed lessons

Lesson::find()->scheduled()->or()->completed()->all(); or

Lesson::find()->or(function($query) { $query->scheduled(); $query->completed(); });

Rails: https://stackoverflow.com/questions/3639656/activerecord-or-query http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-or

senguttuvang avatar Jan 26 '18 13:01 senguttuvang

Sounds reasonable.

samdark avatar Jan 26 '18 15:01 samdark

Hello. ActiveQuery has method orWhere($condition, $params = []). Do you want to make $condition callable?

vladis84 avatar Feb 09 '18 13:02 vladis84