ransack
ransack copied to clipboard
the int column present generate sql do not work on mysql
rails4.2.9
for example:
Student.search(teacher_id_present: 1).result.to_sql
teacher_id is int, so the generate sql is
SELECT `students`.* FROM `students` WHERE `students`.`deleted_at` IS NULL AND (`students`.`teacher_id` IS NOT NULL AND `students`.`teacher_id` != NULL)
So I think
when the column type is int, the arel_values is [nil] not [nil, '']
Or you can give me some tips? to resolve it.
And arel_table not handle this too visitors/to_sql.rb
def visit_Arel_Nodes_NotEqual o, collector
right = o.right
collector = visit o.left, collector
if right.nil?
collector << " IS NOT NULL"
else
collector << " != "
visit right, collector
end
end
Hi @wpzero a failing test against mysql would be awesome. If not possible, I'll eventually write one but this issue will get more attention with it. Cheers.
FYI this happens when using *_present or *_blank in conjunction with a datetime column:
Contact.ransack(created_at_present: true).result.to_sql
Results in
SELECT "contacts".* FROM "contacts" WHERE ("contacts"."created_at" IS NOT NULL AND "contacts"."created_at" != NULL)