ransack icon indicating copy to clipboard operation
ransack copied to clipboard

the int column present generate sql do not work on mysql

Open wpzero opened this issue 8 years ago • 2 comments

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

wpzero avatar Nov 17 '17 08:11 wpzero

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.

scarroll32 avatar Feb 07 '18 15:02 scarroll32

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)

mhssmnn avatar Aug 26 '21 03:08 mhssmnn