#341 incomplete
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:24 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

  • rick

    rick June 5th, 2008 @ 05:52 PM

    • → 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.

  • Ken Collins

    Ken Collins July 6th, 2008 @ 01:37 AM

    • → 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.
  • Brad

    Brad September 15th, 2008 @ 07:26 PM

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

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins