This project is archived and is in readonly mode.
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
-
joel (at developwithstyle) April 30th, 2010 @ 09:10 AM
Ok, so after further investigation, this is ony happenning when the scope is defined within the parent model (Event).
-
Neeraj Singh May 3rd, 2010 @ 05:28 PM
- Tag changed from scope, sti to patch, rails3, scope, sti
Attached is a patch against Rails3 edge along with test.
Please see this gist if you are interested in why the solution is the way it is.
-
José Valim May 3rd, 2010 @ 05:38 PM
- Milestone cleared.
- State changed from new to open
- Assigned user set to José Valim
-
Repository May 15th, 2010 @ 08:51 AM
- State changed from open to resolved
(from [58adc6737126242d189274d83c50bcade098800a]) STI should not ignore type condition while applying scopes from parent class scopes
[#4507 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/58adc6737126242d189274d83c50bc... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to Low
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>
People watching this ticket
Attachments
Referenced by
- 4507 STI ignored with scopes [#4507 state:resolved]
- 1570 named_scope not preserving proper model in STI Assigning this ticket to Mr. Valim . He approved #4507 wh...