Hmm, while the :content property is definitely stored inside the elements table because that’s how STI does its thing, I do think that it’s correct that the Element model (baseclass) does not understand it since it’s actually declared in Textbug model (subclass). At least that’s how I understand inheritance.
Also, the error message explicitly states that there is no such property :content in the Element model, which is true, it’s only in the Textbug model
I’m marking this as not applicable.
For reference, I stripped your script to the minimum (basically I removed the indirection through the additional method since it’s not necessary to show the behavior) and ran it with latest next branch. The error message is better than the one you got with 0.9.11 and imho it’s how it should behave.
ruby
require ’rubygems’
require ’dm-core’
require ’dm-validations’
class Element
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
end
class Textbug < Element
property :content, Text
validates_present :content
end
DataMapper.setup(:default, "sqlite3:///#{Dir.pwd}/content.db")
DataMapper.auto_upgrade!
box = Textbug.create({:content => ’hello’})
Element.all.each do |e|
puts e.content
end
# mungo:snippets snusnu$ ruby 911.rb
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:741:in `assert_valid_fields’: +options[:field]+ entry :content does not map to a property in Element (ArgumentError)
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:732:in `each’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:732:in `assert_valid_fields’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:708:in `assert_valid_options’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:706:in `each’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:706:in `assert_valid_options’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:648:in `initialize’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:354:in `update’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:370:in `merge’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:73:in `reload’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:817:in `reload_attributes’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:802:in `lazy_load’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/property.rb:660:in `send’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/property.rb:660:in `lazy_load’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/property.rb:539:in `get’
# from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model/property.rb:206:in `content’
# from 911.rb:22
# from /opt/local/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/lazy_array.rb:458:in `each’
# from /opt/local/lib/ruby/gems/1.8/gems/extlib-0.9.13/lib/extlib/lazy_array.rb:458:in `each’
# from 911.rb:21
by Martin Gamsjaeger (snusnu)