automatic lifecycle scopes fail in weird ways on STI models
Reported by Matt Jones | August 21st, 2009 @ 10:29 PM | in Hobo 1.0 - Final
Two models: User and SpecialUser < User.
Both have a lifecycle state :inactive.
This works: SpecialUser.inactive
This fails: User.inactive; SpecialUser.inactive
Very short error (called from irb):
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.call
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:102:in `inactive'
from (irb):3</code>
The issue appears to be that the scopes array is not correctly populated.
Comments and changes to this ticket
-
Bryan Larsen August 28th, 2009 @ 02:55 PM
- Tag changed from automatic_scopes, bug, sti to automatic_scopes, defect, sti
- State changed from new to open
-
Matt Jones November 30th, 2009 @ 09:00 PM
The bug is weirder than I thought; the above only works if the SpecialUser model is touched somewhere during the app setup. Complete steps to reproduce:
SpecialUser # loads the constant; this copies User's @inherited_attributes[:scopes] User.inactive # fires method_missing and gets an automatic scope SpecialUser.inactive # => die messily; SpecialUser has inherited the method but not the scope in @inherited_attributes[:scopes]
This may actually be a Rails bug rather than a Hobo issue; we may have just been the first people to trip over it.
For the time being, I've got a workaround, but I'm going to go ahead and ticket it on the Rails LH as the behavior is weird.
-
Matt Jones November 30th, 2009 @ 09:17 PM
- State changed from open to resolved
- Tag cleared.
Resolved in http://github.com/tablatom/hobo/commit/04cfc5b79ff528791e5a4aa352de... - we now hand the scope down to the subclasses.
-
Tom Locke December 1st, 2009 @ 08:09 AM
(from [04cfc5b79ff528791e5a4aa352ded6b9d7e2c94f]) [#492 state:resolved] correctly propagate automatic scopes to subclasses http://github.com/tablatom/hobo/commit/04cfc5b79ff528791e5a4aa352de...
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
People watching this ticket
Referenced by
- 492 automatic lifecycle scopes fail in weird ways on STI models (from [04cfc5b79ff528791e5a4aa352ded6b9d7e2c94f]) [#492 s...