#1050 ✓resolved

:attr.not => [] (empty array) no longer works

Reported by mpd | September 19th, 2009 @ 05:06 AM | in 0.10.2

I was using this for filtering out chat messages that had been sent by people a user has ignored, i.e.

:sender_id.not => user.ignored_users.map { |iu| iu.id }

which now fails for users who haven't ignored anybody.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) September 19th, 2009 @ 11:22 PM

    • State changed from “new” to “confirmed”

    I agree, this is a bug.

    The reason this happens is that when InclusionComparison sees an empty Array, it is invalid. This behavior is correct when someone does :sender_id => [], since nothing can match the empty set.

    However, in this case, since the comparison is negated, everything can match an empty set.

    The difficult part of enabling this logic is that each comparison object doesn't know anything about the container it's in, so it doesn't know if it's negated or not. We could just have it so that when a NotOperation contains an InclusionComparison, the #valid? result is flipped from false to true. However, this won't work in cases where the NotOperation is also included inside a NotOperation, either as an immediate parent or as an ancestor. It also doesn't work for cases like NOT(NOT(NOT(IN()))), etc.

    I think the solution might be for each comparison and operator to have a reference to it's parent, so it can walk up to the root and determine it's context, and whether it should be valid or not. However this will probably require a bit more thought.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 24th, 2009 @ 04:20 AM

    • Assigned user set to “Dan Kubb (dkubb)”
    • Milestone set to 0.10.2
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 24th, 2009 @ 04:40 AM

    • State changed from “confirmed” to “resolved”

    (from [1f515cb71d491b42d86d32b22ede4e4a75c84322]) Allow :attr.not => [] to match all records

    • Each operation and comparison now has a reference to it's parent so that we can determine if a specific comparison is negated. This allows a negated InclusionComparison with an empty Enumerable to match every record. It also allows it to be seen as valid, so that the query actually reaches the datastore.
    • Allow :attr.not => nil to work for attributes that do not allow nil values. Previously this would've been denied because the not-nullable Property would say that the nil is an invalid value.

    [#1050 state:resolved] http://github.com/datamapper/dm-core/commit/1f515cb71d491b42d86d32b...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Referenced by