Reputation: 59
I have a simple time tracker and just trying to write a query that satisfies the following and pulls all records with the following: user_id = 6 AND (is_paused is true OR manual_input_hours is nil).
Based on what I tried to structure as follows
Timerecord.where(user_id: 6).where(Timerecord.where(is_paused: true).or(Timerecord.where.not(manual_input_hours: 0)))
but it doesnt work, getting the following error: Unsupported argument type: #Timerecord::ActiveRecord_Relation:0x000056546f549358 (Timerecord::ActiveRecord_Relation) (ArgumentError)
Upvotes: 1
Views: 48
Reputation: 1323
You have the OR part correct, you just need to combine it with the user query. You can do this with the merge method to get the AND behaviour:
records_for_user = Timerecord.where(user_id: 6)
paused = Timerecord.where(is_paused: true)
has_manual_input = Timerecord.where.not(manual_input_hours: 0)
# records_for_user AND (paused OR has_manual_input)
records_for_user.merge(paused.or(has_manual_input))
Upvotes: 2