This project is archived and is in readonly mode.

#6611 new
Corey Ward

ActiveRecord query changing when a dot/period is in condition value

Reported by Corey Ward | March 24th, 2011 @ 03:00 AM

I have created a barebones Rails app demonstrating this bug: https://github.com/coreyward/bug-demo

I also have a Question open on StackOverflow about this: http://stackoverflow.com/questions/5199235/activerecord-query-chang...

I don't have the skills/knowledge to know A) where this is coming from or B) how to fix it. Any help would be very much appreciated.


This bug occurs when you have a "child" model (one that belongs_to another model) with an order scope on it and you try to set a where condition.

So for the following models:

class Person < ActiveRecord::Base
  has_many :items
end

class Item < ActiveRecord::Base
  belongs_to :person
  default_scope order(:ordinal)
end

With the following calls:

Person.includes(:items).where(:name => 'John')
# or
Person.includes(:items).find_by_name 'John'

The items loaded are ordered by the ordinal on each Item.

If you introduce a period into the name, though (e.g. "John.Smith"), the order scope is ignored.

To see this in action...

$ git clone git://github.com/coreyward/bug-demo.git
$ cd bug-demo
$ rake db:create db:migrate db:seed
$ rails s

And then fire up http://localhost:3000/ and see for yourself.

Comments and changes to this ticket

  • Anuj Dutta

    Anuj Dutta March 24th, 2011 @ 03:44 AM

    • Importance changed from “” to “Low”

    Thanks for such a detailed info and the demo application. Ran the app and can confirm that this is a bug. I am not sure what is causing it yet but I am investigating.

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>

Pages