Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

STI parent collection does not load children properties #246

Open

Description

@rykov

If you have a parent model Foo with a child Bar, and you try to query Foo as a collection, properties of Bar will not be loaded. Here's an example:

require 'rubygems'
require 'dm-core'

DataMapper.setup(:default, :adapter => 'in_memory')

class Foo
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  property :type, Discriminator
end

class Bar < Foo
  property :nick, String
end

DataMapper.finalize

%w(a b c).each do |name|
  b = Bar.new
  b.name = b.nick = name
  b.save
end

coll = Foo.all

puts coll.properties.map(&:name).inspect
coll.each do |f|
  puts "#{f.name} -- #{f.nick}"
end

Which produces the following output. As you see, Bar#nick doesn't get loaded.

[:id, :name, :type]
a -- 
b -- 
c --

I would expect the following output:

[:id, :name, :type, :nick]
a -- a
b -- b
c -- c

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions