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

Outdated doc in `Active Record Query Interface' #24830

Closed
zhengpd opened this issue May 3, 2016 · 3 comments
Closed

Outdated doc in `Active Record Query Interface' #24830

zhengpd opened this issue May 3, 2016 · 3 comments

Comments

@zhengpd
Copy link

zhengpd commented May 3, 2016

The 2.3.1 Equality Conditions doc in Active Record Query Interface page says:

The values cannot be symbols. For example, you cannot do Client.where(status: :active).

But actually the symbols used in where conditions will be converted to strings for querying.

@prathamesh-sonpatki
Copy link
Member

But actually the symbols used in where conditions will be converted to strings for querying.

It does not seem so.

$ rails c
Loading development environment (Rails 5.0.0.beta4)
>> Post.where(name: :title)
  Post Load (0.5ms)  SELECT "posts".* FROM "posts" WHERE "posts"."name" = ?  [["name", :title]]
=> #<ActiveRecord::Relation []>
>> Post
=> Post(id: integer, name: string, content: text, created_at: datetime, updated_at: datetime, member_id: integer, user_id: integer)
>> Post.where(name: :text)
  Post Load (0.1ms)  SELECT "posts".* FROM "posts" WHERE "posts"."name" = ?  [["name", :text]]
=> #<ActiveRecord::Relation []>
>> 

@zhengpd
Copy link
Author

zhengpd commented May 3, 2016

I saw the doc at http://guides.rubyonrails.org/active_record_querying.html#hash-conditions , which is for v4.2.6 right now.

$ rails c
Loading development environment (Rails 4.2.6)
irb(main):001:0> User.where(name: :test_name)
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."name" = ?  [["name", "test_name"]]
=> #<ActiveRecord::Relation []>
irb(main):002:0> 

@vipulnsward
Copy link
Member

This is intentional: activerecord-hackery/squeel#67 (comment)
Its not officially supported, and on master, actually leads to pass symbol, but strings on some previous versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants