This project is archived and is in readonly mode.
Broken find last when no order is given.
Reported by Jan De Poorter | March 4th, 2009 @ 03:43 PM
When finding the last item through an association or a named_scope in an association I get the error:
User.first.logs.find_last_by_type('foo')
NoMethodError: private method `split' called for nil:NilClass
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1540:in `reverse_sql_order'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1529:in `find_last'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:614:in `find'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1907:in `find_last_by_credits'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1892:in `send'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1892:in `method_missing'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:374:in `send'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:374:in `method_missing'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:2148:in `with_scope'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:206:in `send'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:206:in `with_scope'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:370:in `method_missing'
from (irb):5
I tracked it down to scoped? returning true because the :order key was set by the association, but was nil. Attached is a patch that fixes that by checking if the key is there and is not nil
Comments and changes to this ticket
-
Pratik March 6th, 2009 @ 10:22 AM
- Assigned user set to Pratik
- Milestone cleared.
-
Ryan Angilly March 6th, 2009 @ 03:00 PM
Was this problem recently introduced? This seems like a big problem. Raises flags that something this big would be broken this late in the RC cycle. More odd that the current set of tests didn't catch it.
-
Repository March 9th, 2009 @ 12:02 PM
- State changed from new to committed
(from [277c799d58be4b3e0e885d7b3fd6d954facc111b]) Fix find_by_last when order is given [#2127 state:committed]
Signed-off-by: David Heinemeier Hansson david@loudthinking.com http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 2127 Broken find last when no order is given. (from [277c799d58be4b3e0e885d7b3fd6d954facc111b]) Fix fin...