7 Kudos

DataMapper: Parent / Child Relationship

I couldn't find an example at datamapper.org /docs for a parent child relationship.
After a little searching, I found the answer in the integration tests.  Here is the example:

class Node
include DataMapper::Resource

def self.default_repository_name
ADAPTER
end

property :id, Integer, :serial => true
property :name, String

has n, :children, :class_name => 'Node', :child_key => [ :parent_id ]
belongs_to :parent, :class_name => 'Node', :child_key => [ :parent_id ]

end

Hope that helps someone else.
Sponsors
Sponsors
About the Author

7 Kudos
Top Entertainment Articles
Lindsay Lohan's Assistant Worries Lindsay Will Kill Herself
In yet another recording released by Lindsay's dad Michael, her assistant Jenni Muro says, "I am trying to save your daughter's life every day." Wait, Lindsay Lohan has an assistant?
Twilight’s Christian Serratos Gets Naked For PETA
Serratos poses naked for the 'I'd Rather Go Naked Than Wear Fur' campaign.
100 Best Bikini Bodies
Click here for the best way to spend 10 minutes.
More From Zimbio
Copyright © 2009 - Zimbio, Inc. Some rights reserved.