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
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
-
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 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 Gessler September 15th, 2008 @ 07:25 PM
I just got bit by this as well because of the outdated rails docs.
-
josh December 20th, 2008 @ 05:06 PM
- no changes were found...
-
Ryan Bigg April 10th, 2010 @ 08:37 AM
- Assigned user set to josh
This is no longer an issue on Rails 2.3.5 or Rails 3.0.0 beta 2.
-
josh April 11th, 2010 @ 07:09 PM
- Assigned user cleared.
-
Ryan Bigg April 11th, 2010 @ 09:54 PM
- State changed from incomplete to invalid
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>