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

STI parent collection does not load children properties #246

Open
rykov opened this issue Apr 7, 2013 · 0 comments
Open

STI parent collection does not load children properties #246

rykov opened this issue Apr 7, 2013 · 0 comments

Comments

@rykov
Copy link

rykov commented Apr 7, 2013

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant