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.

default_scope, :order => :symbol, and Model.last conflict.

#2024

The problem occurs when using a symbol to define order in default_scope, and then calling Model.last.


# location.rb
default_scope :order => :descriptive_name

# console
>> Location.last
NoMethodError: private method `split' called for :descriptive_name:Symbol
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.0/lib/active_record/base.rb:1537:in `reverse_sql_order'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.0/lib/active_record/base.rb:1526:in `find_last'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.0/lib/active_record/base.rb:614:in `find'
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.0/lib/active_record/base.rb:629:in `last'
  from (irb):4

# But strings work:
default_scope :order => 'descriptive_name'

>> Location.last
# => works correctly

Model.first and other things I have tried work as expected.

Reported by Zef Houssney · February 20th, 2009 @ 12:02 AM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Rob Anderton
    Rob Anderton
    • Tag set to active_record, bug, find_last, order, patch

    I also hit this bug today, I've attached a simple patch that fixes the problem along with an extra test case.

    March 8th, 2009 @ 11:16 PM

  2. Repository
    Repository
    • State changed from new to resolved

    (from [faf4ba6b79e56dde383a8761fb1f485fcd07c72b]) Allow find(:last) :order be a symbol [#2024 default_scope, :order => :symbol, and Model.last conflict. state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    March 9th, 2009 @ 01:30 PM