(Note: I haven't used DataMapper much since I handed the reigns over to WanWizard, but I maintained DMZ for quite a while.)
I see two possible solutions:
1) Assuming any two vertexes can only have one common edge
In the case of a single edge per vertex pair, you don't need to do anything special. Simply create a new standard self-relationship (ie: a named one) to represent the connection:
$has_many = array(
'parent_category' => array(
'class' => 'category'
'other_field' => 'category'
),
'category' => array(
'other_field' => 'parent_category'
)
);
Then create your joining table like this:
name: categories_parent_categories
columns: id | category_id | parent_category_id
Now you can easily make your edges like this:
$catA = new Category()
$catA->name = 'catA';
$catA->save();
$catB = new Category();
$catB->name = 'catB';
$catB->save();
$catA->save('parent_category', $catB);
// OR
$catA->save_parent_category($catB);
$catA->parent_category->get();
foreach($catA->parent_category as $parent) {
echo $parent->name;
}
See http://datamapper.wanwizard.eu/pages/save.html#Advanced for more info on saving these kinds of relationships.
2) Assuming you need multiple edges per vertex
This is a much more complicated example, but it basically involves creating a dedicated object to represent the relationship, because DataMapper doesn't allow two objects to be related more than once per relationship type.
If you want this example, let me know, and I'll write something up, or check out http://datamapper.wanwizard.eu/pages/troubleshooting.html#Relationships.NtoM