Skip to content

present predicate doesn't seem to work as defined in the documentation #1552

Open
@dvkch

Description

@dvkch

Hi there,

I am trying to add a simple filter on a string column to an ActiveAdmin page. I already have the standard "contains/equals/etc" filter defined as filter :dsp_isrc, I am currently trying to add filter :dsp_isrc_present, as: :boolean, but this doesn't work as expected :

  • when choosing "Yes", it doesn't return anything, although i do have Artists where this attribute is filled
  • when choosing "No", it returns the proper list of Artists.

I think I was able to reduce the problem to this discrepancy :

my-project(dev)> Artist.ransack(dsp_isrc_present: '1').result.to_sql
=> "SELECT \"artists\".* FROM \"artists\" WHERE (\"artists\".\"dsp_isrc\" IS NOT NULL AND \"artists\".\"dsp_isrc\" != NULL)"

my-project(dev)> Artist.ransack(stripe_customer_id_present: '1').result.to_sql
=> "SELECT \"artists\".* FROM \"artists\" WHERE (\"artists\".\"stripe_customer_id\" IS NOT NULL AND \"artists\".\"stripe_customer_id\" != '')"

Suprisingly, one case ends up with a != NULL and the other with != '', the latter being correct according to the documentation.

I think the != NULL would explain why my list ends up empty when choosing "yes" in ActiveAdmin, since NULL equality always surprises me.

Both columns are defined identically in my schema, although they do have different indexes.

  create_table "artists", force: :cascade do |t|
    ...
    t.string "stripe_customer_id"
    t.string "dsp_isrc"
    t.index ["dsp_isrc"], name: "index_artists_on_dsp_isrc", unique: true, where: "(dsp_isrc IS NOT NULL)"
  end

I'd be very interested in understanding how i could fix this issue. Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions