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.

RC1 to RC2 regression : multilines where conditions autojoin with "AND"

#5436

Hi,

the behaviour when using multilines where conditions is different between Rails 3 RC1 and Rails 3 RC2.

class User < ActiveRecord::Base
    scope :test_scope,
               where("active = ?
                      and login like ?", true, "%test%")
end
$-> rails c
Loading development environment (Rails 3.0.0.rc)
irb(main):001:0> User.test_scope.to_sql
"SELECT     \"users\".* FROM       \"users\" WHERE     (active = 't'\n                      and login like '%test%')"
$-> rails c
Loading development environment (Rails 3.0.0.rc2)
irb(main):001:0> User.test_scope.to_sql
"SELECT     \"users\".* FROM       \"users\"  WHERE     (active = 't'\n AND                       and login like '%test%')"

As you can see in RC2, it autojoins split lines with "AND" and results in faulty SQL.

Reported by Nicolas Blanco · August 24th, 2010 @ 10:57 AM

State: duplicate
Milestone: none
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. oleg dashevskii
    oleg dashevskii

    Got bitten by it too. Quick workaround is to add backslash:

    class User < ActiveRecord::Base
        scope :test_scope,
                   where("active = ? \
                          and login like ?", true, "%test%")
    end
    

    August 24th, 2010 @ 01:40 PM

  2. Brandon Tilley
    Brandon Tilley

    It appears that this only happens for certain adapters. In particular, I did not have this problem on my local development machine using SQLite, but when I pushed to Heroku (which uses PostgreSQL) the bug manifested itself.

    August 24th, 2010 @ 04:34 PM

  3. Thong Kuah
    Thong Kuah
    • Tag changed from arel activerecord bug rails3, activerecord, arel, rails3 to arel activerecord bug rails3, line break, activerecord, arel, rails3

    August 24th, 2010 @ 11:12 PM

  4. Thong Kuah
    Thong Kuah
    • Tag changed from arel activerecord bug rails3, line break, activerecord, arel, rails3 to arel activerecord bug rails3, line break, activerecord, arel, multiline, rails3

    August 24th, 2010 @ 11:13 PM

  5. oleg dashevskii
    oleg dashevskii

    So, the bug confirmed with MySQL and PostgreSQL adapters.

    August 25th, 2010 @ 06:09 AM

  6. oleg dashevskii
  7. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to duplicate
    • Importance changed from to Low

    August 26th, 2010 @ 03:50 AM

  8. Anil Wadghule
    Anil Wadghule
    • Tag cleared.

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:10 AM

  9. Aditya Sanghi
    Aditya Sanghi

    Automatic cleanup of spam.

    October 12th, 2010 @ 10:15 AM