ruby on rails - 'Where-in' query in postgresql for two different queries showing same result -
i have active record assosciation relation follows.
@tasks = #<activerecord::associationrelation [#<task id: 3130, title: "commit @ least 1 small win today", content: "when check-in on app lets me acknowledge m...",created_at: "2016-01-13 01:36:15", updated_at: "2016-01-13 04:47:57", state: "active", #<task id: 3131, title: "purposefully walk 3 minutes ", content: "more ordinary day, choose 5 minutes ...", created_at: "2016-01-13 04:52:32", updated_at: "2016-01-13 04:56:22", state: "active", #<task id: 3132, title: "1km walk or run sunday", content: "i pick direction, start 10 minute warm up,...", created_at: "2016-01-13 04:56:05", updated_at: "2016-01-13 04:56:05", state: "active",#<task id: 3249, title: "1km walk or run wednesday", content: "i pick direction, start 10 minute warm up,...", created_at: "2016-01-24 23:23:34", updated_at: "2016-01-24 23:23:34", state: "active"]> @array = [] @tasks.each |task| if (condition) @array << task.id end @tasks = @tasks.where.not('tasks.id in (?)',@array)
if non empty value in @array,
above condition working fine.
if @array = [] i,e empty array,
@tasks = @tasks.where.not('tasks.id in (?)',@array) not giving me correct result.
also, @tasks = @tasks.where('tasks.id in (?)',@array), condition removing 'not' giving same result when not present when array []
@habits = @habits.where.not('habits.id in (?)',@id_s) ====> output => [] @habits = @habits.where('habits.id in (?)',@id_s) ====> output => [] both returning same optput if @id_s []
why these queries returning same value 2 different conditions?
if rails version date should switch hash notation, handles special cases empty arrays you:
@tasks = @tasks.where.not(id: @array)
Comments
Post a Comment