robs
unread,Jun 30, 2009, 9:34:55 PM6/30/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DataMapper
For example:
class Person
include DataMapper::Resource
property :id, Integer, :serial => true
property :first_name, String, :nullable => false
property :last_name, String
has n :posts
end
class Post
include DataMapper::Resource
property :id, Integer, :serial => true
property :title, String, :nullable => false
property :body, Text
belongs_to :author, :class_name => "Person"
end
What would be the best way to validate the presence of an author when
a post is saved? I noticed that the documentation says that some
validations are automatically inferred (e.g., if :nullable => false
or :length is specified). Is there any way to include this validation
in the belongs_to method call? If not, what would anyone suggest?
Thanks!