Hello Everyone,
I wanted to set some default values for a model. It took me a while
but I finally got it to work but I was wondering if there's a better
way to do the following (please see the "after :save" part):
class User
include DataMapper::Resource
property :username, String, :key => true
property :password, String
has 1, :calendar
has n, :contexts
after :save do
must_save = false
if self.contexts.first({:name => 'uncategorized'}).nil?
self.contexts.new({:name => 'uncategorized'})
must_save = true
end
if self.calendar.nil?
self.calendar = Calendar.new
must_save = true
end
save if must_save
end
end
Thanks for the help!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---