brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

`nil` Scope Condition Causes Loss of Scope #390

Closed sshaw closed 3 years ago

sshaw commented 3 years ago

Version: 1.0.3 Active Record: 5.2.3

# Foo
acts_as_list scope: :owner

# ...

Foo.create(:owner => Owner.first)

Adds the following SQL criteria:

WHERE "foos"."owner_id" = $1 AND ("foos"."position" IS NOT NULL)

But when scoping to a column (sorta like the example in the docs):

# Foo
acts_as_list scope: [:owner, :discarded_at => nil] 

# ...

Foo.create(:owner => Owner.first)

The following criteria is added;

WHERE "foos"."owner_id" IS NULL AND "foos"."discarded_at" = $1 AND ("foos"."position" IS NOT NULL)
--- $1 = ["discarded_at", nil]
brendon commented 3 years ago

Without checking, I think you need to add _id to any columns within an array scope (it's a hangup from the old days where you could omit the _id from a symbol scope and it would be added on):

acts_as_list scope: [:owner_id, :discarded_at => nil]

Let me know if that doesn't work though.

If it interests you, here's where scopes are defined: https://github.com/brendon/acts_as_list/blob/master/lib/acts_as_list/active_record/acts/scope_method_definer.rb

sshaw commented 3 years ago

Hi, thanks. I thought that was attempted but I do see that it is working now with _id.