#64 ✓resolved
Jérôme

default_scope incompatibility

Reported by Jérôme | March 6th, 2009 @ 01:11 PM

Hello

Today's searchlogic trunk is incompatible with the new activerecord's default_scope

default_scope :order => :name raises a "private method gsub!' called for :name:Symbol" in searchlogic/lib/searchlogic/search/ordering.rb:67:inorder_as='

default_scope :order => "name" raises a "can't convert nil into String" in searchlogic/lib/searchlogic/search/ordering.rb:67:in gsub!'

I can't figure out why it doesn't work

Regards

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson March 23rd, 2009 @ 02:55 AM

    • State changed from “new” to “open”

    The second error is very strange. I have never seen symbols accepted in the order option for ActiveRecord. Anyways, that makes no sense because of this:

    if order
      @order.gsub!(/(ASC|DESC)/i, value)
    end
    

    I can't call order directly because other methods get triggered when that is changed, so I call the variable directly. Anyways, its not possible for that value to be nil.

  • Jérôme

    Jérôme March 26th, 2009 @ 10:48 AM

    I found another CRITICAL bug which only affects default_scope and not named_scope: using a column modifier will raise a DB error upon the first model load and until you are using a named_scope ! Check out the weird SQL query produced where conditions are called then twice !

    
    class City < ActiveRecord::Base
      default_scope :conditions => { :country_not => "UK" }
      named_scope :is_capital, :conditions => { :capital => true }
    end
    
    
    Loading development environment (Rails 2.3.2)
    >> City.first
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: cities.country_not: SELECT * FROM "cities" WHERE ("cities"."country_not" = 'UK') LIMIT 1
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in `execute'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:402:in `catch_schema_changes'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in `execute'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:305:in `select'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1510:in `find_initial'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:613:in `find_without_searchlogic'
    	from /opt/local/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:23:in `find'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:623:in `first'
    	from (irb):1
    
    >> City.first
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: cities.country_not: SELECT * FROM "cities" WHERE ("cities"."country_not" = 'UK') LIMIT 1
    
    >> City.is_capital.first
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: cities.country_not: SELECT * FROM "cities" WHERE ((("cities"."country_not" = 'UK' AND "cities"."capital" = 't')) AND ("cities"."country" != 'UK')) LIMIT 1
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in `execute'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:402:in `catch_schema_changes'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in `execute'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:305:in `select'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1510:in `find_initial'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:613:in `find_without_searchlogic'
    	from /opt/local/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:23:in `find'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:183:in `send'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:183:in `method_missing'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in `with_scope_without_searchlogic'
    	from /opt/local/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:47:in `with_scope'
    	from (__DELEGATION__):2:in `__send__'
    	from (__DELEGATION__):2:in `with_scope'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:182:in `method_missing'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in `with_scope_without_searchlogic'
    	from /opt/local/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:47:in `with_scope'
    	from (__DELEGATION__):2:in `__send__'
    	from (__DELEGATION__):2:in `with_scope'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:179:in `method_missing'
    	from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:137:in `first'
    	from (irb):3
    	
    >> City.is_capital.first
    => #<City id: 1, name: "Paris", country: "FR", capital: true, created_at: "2009-03-26 14:39:29", updated_at: "2009-03-26 14:39:29">
    
  • Jérôme

    Jérôme March 26th, 2009 @ 10:57 AM

    Please note that mixing named_scope with default_scope will injects twice the same default_scope condition in the SQL query (AR bug).

  • Ben Johnson

    Ben Johnson March 30th, 2009 @ 11:50 AM

    Can you please create a failing test(s), and then I can fix the issue. By test, I mean a test I can run in the searchlogic test suite. I apologize for asking you to do this, but its a new policy I am implementing with my open source projects. I am just very busy and this would help me easily knock out the issue.

  • schof

    schof May 19th, 2009 @ 11:32 AM

    It looks like this comes up for a default scope using :order but only when the search results are empty. I'll see if I can add a test later.

  • Ben Johnson

    Ben Johnson July 30th, 2009 @ 01:37 PM

    • State changed from “open” to “resolved”

    This should be fixed in 2.0. Thanks!

  • frank butler

    frank butler June 22nd, 2019 @ 07:16 AM

    There are some people who are talking about default_scope incompatibility, but the stuff mentioned here is a bit vague. I worked at edubirdie reviews last month. It would be great if someone adds some more facts here so people would be able to get the most of it and understand its essence without making any guesses.

  • frank butler

    frank butler July 10th, 2019 @ 09:18 AM

    Here you can check all point of the comment then you will realize that this is a great plate form where you can discuss the important point of the programming then you will also check all discussion of the many people on the important point of the programming. The design of the site is very good for the users and students, it is very easy to bankatutorial.com understand and language is very easy in which the writer post the comments.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

Provides common named scopes and object based searching.

People watching this ticket

Attachments

Pages