
STI-bug when trying to fetch objects of subclass
Reported by Sindre Aarsaether | May 1st, 2008 @ 05:03 PM
The spec found here pretty much describes it (check out "should not select parent type"). When you try to fetch objects of a subclass, it also fetches all objects of the parentclass.
Comments and changes to this ticket
-
Sindre Aarsaether May 1st, 2008 @ 06:17 PM
I rembered that ssmoot told me something about it on irc, so I guess it's more a missing implementation than a flat-out bug :-)
"ssmoot: so yeah, the thing missing is that the sub-classes need to have a default scope like so: property :type, Class, :default => lambda { |p,r| p.model }, :query => { :type => self }"
-
Sam Smoot May 9th, 2008 @ 12:06 AM
- Milestone cleared.
- Assigned user set to Sam Smoot
Dan explained this to me. It should be as simple as:
scope_stack << { :type => self.class.name }
In the sub-classes. We'll patch it up, re-organize this stuff into a dm-more plugin shortly.
-
Sam Smoot May 9th, 2008 @ 11:14 AM
- Assigned user changed from Sam Smoot to Adam French
Actually, why don't you give this a go Adam?
I think a Custom Type similar to what you did for paranoia would be great.
property :type, DM::Discriminator
FYI, "Discriminator" comes from Hibernate. I like it. It sounds cool. So I think we should go with it since we don't want to go with anything like SingleTableInheritance.
-
-
Sam Smoot May 9th, 2008 @ 04:59 PM
Since we'll need to take advantage of our new ::bind method, this needs to be a custom-type since I don't want to add a Class::bind. I've learned my lesson messing too much with Class. ;-)
-
Sindre Aarsaether May 9th, 2008 @ 06:44 PM
Have you looked at the last spec there to? Will STI support nested subclasses in the future? Selecting Bully.all should select all that have type 'Bully', AND type .. for every subclass of bully? I don't know how one would / could implement that atm, but it could be an idea to try to include.
-
Sindre Aarsaether May 9th, 2008 @ 06:44 PM
Hmm, the link I supplied in the ticket is wrong (its an old version). Check out the full spec here . That last spec there is the one I am referring to in my comment above..
-
Sindre Aarsaether May 19th, 2008 @ 06:50 PM
- State changed from new to resolved
I've now added full STI-support in core with Discriminator.
class Person property :type, Discriminator end
This now adds all logic, making nested inherits etc work. If Sam wants to move it out into dm-discriminator it's okay for me, but I really think it is useful enough to be in core.
Resolved.
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 »