#228 ✓resolved
Sindre Aarsaether

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

    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

    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

    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.

  • Adam French

    Adam French May 9th, 2008 @ 03:42 PM

    what happened to

     property :type, Class
  • Sam Smoot

    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

    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

    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

    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 

    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.


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.

New-ticket Create new ticket

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