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

Attribute query method documentation is misleading #16246

Closed
asterite opened this issue Jul 21, 2014 · 5 comments
Closed

Attribute query method documentation is misleading #16246

asterite opened this issue Jul 21, 2014 · 5 comments
Labels

Comments

@asterite
Copy link

According to the documentation, "Query methods allow you to test whether an attribute value is present". However:

irb(main):001:0> Site
=> Site(id: integer, lat: decimal, lng: decimal, created_at: datetime, updated_at: datetime)
irb(main):002:0> s = Site.new; s.lat = 0; s.lat?
=> false
irb(main):003:0> s.lat.present?
=> true

This is very confusing. The documentation should be updated to show that for numeric values zero will return false. And it shouldn't include the word present, as people would associate it with the present? method. And it should probably explain why there is a different behaviour for numerics (I don't know why).

@s-aida
Copy link
Contributor

s-aida commented Jul 22, 2014

I always think if an attribute is numeric and has the default value, it should return whether the current value equals the default value, rather than zero, but at the same time I feel not many people may use these methods....

@senny senny closed this as completed in a09f025 Jul 28, 2014
@senny
Copy link
Member

senny commented Jul 28, 2014

@asterite updated the docs accordingly. This behavior goes waaaay back (db045db, https://github.com/rails/rails/blob/db045db/activerecord/lib/active_record/base.rb#L903-L904) and will need a good reason to change. If you want to get more opinions about that, please use the rails-core mailing list to suggest that change.

Thank you for reporting 💛

@rafaelfranca
Copy link
Member

In fact we already have the discussion about this same thing on the Rails
core mailing list. Make sure you read all the tread before suggesting this
change again.
On Jul 28, 2014 12:36 PM, "Yves Senn" notifications@github.com wrote:

@asterite https://github.com/asterite updated the docs accordingly.
This behavior goes waaaay back (db045db
db045db,

https://github.com/rails/rails/blob/db045db/activerecord/lib/active_record/base.rb#L903-L904)
and will need a good reason to change. If you want to get more opinions
about that, please use the rails-core mailing list to suggest that change.

Thank you for reporting [image: 💛]


Reply to this email directly or view it on GitHub
#16246 (comment).

@asterite
Copy link
Author

@senny thanks!

@rafaelfranca do you have a link to that discussion? I opened this issue because we had a bug in our app because of this strange behaviour and I'd like to understand better why it is like that.

@rafaelfranca
Copy link
Member

No, sorry. Try to search at the Rails Core google groups.

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

No branches or pull requests

4 participants