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.

Calling 'last' on a has_many assoication where the order is specified as a symbol raises an error

#341

Calling 'last' on a has_many assoication where the order is specified as a symbol raises an error. This worked prior to Rails 2.1. To recreate define a model with a has_many:

class Train < ActiveRecord::Base
  has_many :cars, :order => :position
end

>> t=Train.first
=> #<Train id: 1, name: "123", created_at: "2008-06-05 15:53:46", updated_at: "2008-06-05 15:53:46">
>> t.cars.last
NoMethodError: private method `split' called for :position:Symbol
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1324:in `reverse_sql_order'
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1310:in `find_last'
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:535:in `find'
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:47:in `find'
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:64:in `last'
	from (irb):2

If you specify :order => 'position' the error does not occur.

Reported by Bill Siggelkow · June 5th, 2008 @ 05:53 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Rick
    Rick
    • State changed from new to incomplete

    I wouldn't call this a bug, I don't think :order was ever meant to take symbols. But, feel free to submit a tested patch so that the problem doesn't come up again.

    June 5th, 2008 @ 05:52 PM

  2. Ken Collins
    Ken Collins
    • Tag cleared.
    • 1 on this... I can try to put together a patch too. This just bit me today and a lot of older docs for rails has some examples where a symbol is used.

    July 6th, 2008 @ 01:37 AM

  3. Brad Gessler
    Brad Gessler

    I just got bit by this as well because of the outdated rails docs.

    September 15th, 2008 @ 07:25 PM

  4. josh
    josh
    • No changes were found…

    December 20th, 2008 @ 05:06 PM

  5. Ryan Bigg
    Ryan Bigg
    • Assigned user set to josh

    This is no longer an issue on Rails 2.3.5 or Rails 3.0.0 beta 2.

    April 10th, 2010 @ 08:37 AM

  6. josh
    josh
    • Assigned user cleared.

    April 11th, 2010 @ 07:09 PM

  7. Ryan Bigg
    Ryan Bigg
    • State changed from incomplete to invalid

    April 11th, 2010 @ 09:54 PM