Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Broken find last when no order is given.

#2127

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

Reported by Jan De Poorter · March 4th, 2009 @ 03:43 PM

State: committed
Milestone: none
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. Eloy Duran
    Eloy Duran

    Patch applies, tests run, and fixes issue.

    +1

    March 4th, 2009 @ 03:52 PM

  2. Jan De Poorter
    Jan De Poorter

    Updated the testname to reflect the intent of the test.

    March 4th, 2009 @ 04:13 PM

  3. Pratik
    Pratik
    • Assigned user set to Pratik
    • Milestone cleared.

    March 6th, 2009 @ 10:22 AM

  4. Ryan Angilly
    Ryan Angilly

    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.

    March 6th, 2009 @ 03:00 PM

  5. Repository
    Repository
    • State changed from new to committed

    (from [277c799d58be4b3e0e885d7b3fd6d954facc111b]) Fix find_by_last when order is given [#2127 Broken find last when no order is given. state:committed]

    Signed-off-by: David Heinemeier Hansson david@loudthinking.com http://github.com/rails/rails/co...

    March 9th, 2009 @ 12:02 PM