#1456 ✓not-applicable
Nicolas G.

STI object instantiation from base class

Reported by Nicolas G. | December 15th, 2010 @ 09:25 AM | in 1.1

Using a simple STI hierarchy with DataMapper 1.0.2:

class Person
  include DataMapper::Resource
  
  property :name, String
  property :type, Discriminator
end

class Father < Person
  property :kids, Integer
end

class Son < Person; end

When I instantiate a Father by its base class:

p= Person.first(:name => 'Daddy')
I get a Father instance but with its property 'kids' marked as immutable. Trying to access it trows an 'Immutable resource cannot be lazy loaded' exception.

The workaround I found is reloading the object from its class:

p = p.class.get(p.id)
but this is obviously not optimal.

Comments and changes to this ticket

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) January 12th, 2011 @ 11:48 AM

    • Milestone set to 1.1
    • State changed from “new” to “not-applicable”
    • Milestone order changed from “196312” to “0”

    I can't reproduce this on current master, see http://pastie.org/1453224

  • Nicolas G.

    Nicolas G. January 25th, 2011 @ 01:43 PM

    You are right, it was only happening when I was redefining the id property on the child class which was obviously an error on my side:

    class Person
      include DataMapper::Resource
    
      property :id,   Serial
      property :name, String
      property :type, Discriminator
    end
    
    class Father < Person
      property :id,   Serial # Shouldn't do this
      property :kids, Integer
    end
    

    Thanks a lot for the response and I will try to be more methodical on my bug reports from now on.

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 »

Pages