This project is archived and is in readonly mode.

#4507 ✓resolved
joel (at developwithstyle)

STI ignored with scopes

Reported by joel (at developwithstyle) | April 30th, 2010 @ 02:58 AM | in 3.0.2

Using Rails3 edge, I have created an Event model with the following scope:

scope :active, where([ "start > ?", 2.hours.ago ])

Then I extend that model to use STI with two further models: Conference and QaSession.

Now when I run the following it works:

ruby-1.9.2-head > Conference.all
  SQL (0.4ms)  SHOW TABLES
  Conference Load (0.4ms)  SELECT `events`.* FROM `events` WHERE (`events`.`type` = 'Conference')

But when I use the 'active' scope:

ruby-1.9.2-head > Conference.active
  Event Load (0.5ms)  SELECT `events`.* FROM `events` WHERE (start > '2010-04-29 23:52:41')

As you can see when calling the scope method, the STI part of the SQL query is not included at all. The query should be:

SELECT `events`.* FROM `events` WHERE (start > '2010-04-29 23:52:41') AND (`events`.`type` = 'Conference')

I am pretty sure that this is a bug, as I don't think I am setting and calling the scope incorrectly. thx.

Comments and changes to this ticket

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>

Referenced by

Pages