I'm just getting started with DataMapper and I'm trying to figure out why you need to specify a has
and a belongs_to
.
For instance, look at the example on the DataMapper website. Isn't this redundant? If Post has n
comments, then doesn't Comment automatically belongs_to
post? Why do I have to specify this?
class Post
include DataMapper::Resource
property :id, Serial
has n, :comments
end
class Comment
include DataMapper::Resource
property :id, Serial
property :rating, Integer
belongs_to :post # defaults to :required => true
def self.popular
all(:rating.gt => 3)
end
end