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

Ransack doesn't handle attribute names including "and" / "or" #299

Closed
seanlinsley opened this issue Nov 7, 2013 · 6 comments · Fixed by #562
Closed

Ransack doesn't handle attribute names including "and" / "or" #299

seanlinsley opened this issue Nov 7, 2013 · 6 comments · Fixed by #562

Comments

@seanlinsley
Copy link
Contributor

Starting from: activeadmin/activeadmin#2669

If you have a foo_and_bar attribute on a model, this should work:

Model.search(foo_and_bar_eq: 'baz').result

My best guess is that right now the logic that allows this:

User.search(first_name_or_last_name_eq: 'baz').result
SELECT "users".* FROM "users" WHERE (("users"."first_name" = 'baz' OR "users"."last_name" = 'baz'))

Is skipping past existing attributes, and likely also skipping past existing ransackers.

@avit
Copy link
Contributor

avit commented Nov 14, 2013

What would break if we made ransack split on __and__ / __or__ (two underscores)?

@avit
Copy link
Contributor

avit commented Nov 14, 2013

@seanlinsley Keep in mind you can build your query from hashes, this is what ransack does when parsing it internally:

Model.search( c: [{a: ["first_name_or_last_name"], p: "eq", v: ["baz"]}] )

@seanlinsley
Copy link
Contributor Author

I'm not actually running into this problem myself because I don't have any attributes with "and" / "or" in the name.

I only attempted a fix to force myself to better understand how Ransack works.

Is it possible to build a ransacker with the hash syntax?

@avit
Copy link
Contributor

avit commented Nov 14, 2013

Well, you could set up a ransacker to cover the right column name; not sure how you'd want to actually use it with the hash syntax though:

ransacker :name_parts do
  arel_table[:first_name_or_last_name]
end

@seanlinsley
Copy link
Contributor Author

This was resolved by #449

@seanlinsley
Copy link
Contributor Author

Apparently not: #302 (comment)

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

Successfully merging a pull request may close this issue.

2 participants