This project is archived and is in readonly mode.

#341 ✓invalid
Bill Siggelkow

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

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

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.

Comments and changes to this ticket

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>

Pages