Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour between Symbol and Array scopes #155

Closed
alavrard opened this issue Feb 12, 2015 · 1 comment
Closed

Inconsistent behaviour between Symbol and Array scopes #155

alavrard opened this issue Feb 12, 2015 · 1 comment

Comments

@alavrard
Copy link

Hello,

When a symbol is passed to an association, the scope column is inferred from the symbol:

class TodoItem < ActiveRecord::Base
  belongs_to :todo_list
  acts_as_list scope: :todo_list
end
configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/

=> will give a scope on "todo_list_id"

If the scope is an array, the name passed as an argument is used, without adding the _id suffix:

class TodoItem < ActiveRecord::Base
  belongs_to :todo_list
  acts_as_list scope: [:todo_list]
end

=> the scope is now "todo_list". The scope is then created with:

memo[column.intern] = read_attribute(column.intern); memo

... but read_attribute on an association getter returns nil, which will give a query with todo_list_id IS NULL.

I don't know what the best solution would be... An easy fix could be to use send(column.intern) instead of read_attribute(column.intern).

Another one would be to determine if the scope column is an association or not, with reflect_on_association, which could also be used to determine the foreign key instead of just appending _id to the name.

@brendon
Copy link
Owner

brendon commented Apr 17, 2016

Hi @ArnaudL, is this still an issue for you? I think this behaviour is consistent right back to the early days of acts_as_list. The scope feature has always been a bit of a mind job.

Unfortunately we don't have time to work on new features like this at the moment. If you'd like to provide a PR with some tests then we'll definitely work with you on it, but otherwise I'm going to close this for now. :)

@brendon brendon closed this as completed Apr 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants