What version of DataMapper are you on? This works just fine in 1.0
>>>>>>
require "rubygems"
require "data_mapper"
require "active_support/core_ext"
DataMapper.setup(:default, "sqlite::memory:")
class Human
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
property :name, String
property :birthdate, Date
end
class Person < Human; end
class Woman < Human; end
class Man < Human; end
class Child < Human; end
Human.auto_migrate!
# Create all the generic People
Person.create(:name => "Paul", :birthdate => Date.today - 30.years)
Person.create(:name => "Mary", :birthdate => Date.today - 35.years)
Person.create(:name => "Pat", :birthdate => Date.today - 3.years)
# Filter all the generic people into "real" subclass types
Person.each {|p| p.update!(:type => "Man") if p.name == "Paul" }
<<<<<
On Sep 22, 1:03 pm, cthree <[email protected]> wrote:
> I have an application which reads in a large log file in a known
> format where each entry in the log maps to a specific class. I'm
> modeling it using STI where I have a "generic" type to hold the log
> entries and store them in the database in a single table. Then I have
> a background thread which goes through each generic log entry and
> further categorizes them into more concrete subclass types.
>
> It looks something like this:
>
> class Human
> include DataMapper::Resource
> property :id, Serial
> property:type, Discriminator
> property :name, String
> property :birthdate, Date
> end
>
> class Person < Human; end
> class Woman < Human; end
> class Man < Human; end
> class Child < Human; end
>
> ...
>
> # Create all the generic People
> Person.create(:name => "Paul", :birthdate => Time.now - 30.years)
> Person.create(:name => "Mary", :birthdate => Time.now - 35.years)
> Person.create(:name => "Pat", :birthdate => Time.now - 3.years)
>
> # Filter all the generic people into "real" subclass types
> Person.each {|p| p.update!(:type => "Man") if p.name == "Paul" &&
> Time.now - p.birthdate >= 18.years
>
> When I try something similar in my app I get:
>
> ArgumentError - The attribute 'type' is not accessible in Person
>
> Can anyone give me some advice on how to make this work? Is there some
> trick to changing the sti type after it is already saved?
>
> Thanks!
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.