You caught it while I was writing out the response. Good for you! Take a look at the second part of the response, that should still be relevant.
cheers,
------- ORIGINAL POST starts here ...
The problem is in how you've defined the relationship. You've forgotten to define the other side of the relationship -- you still got it saying post => ... it should be category =>
Updating that should get the code to work.
Code:
<?php
class Category extends DataMapper
{
var $table = "categories";
var $has_many = array(
'subcateg' => array(
'class' => 'category',
'other_field' => 'category'
),
'post' => array( // This needs to be 'category' => array ... NOT post!
'other_field' => 'subcateg'
)
);
function __construct($id = NULL)
{
parent::__construct($id);
}
}
?>
Also, in your data structure, every sub category can have multiple parent categories, is that correct??
So subcat2 has both parent_2 and parent_1 ... that's how your relationship is setup at the moment.
If you don't want it to work like this, then you need to make it a one to many relationship, where every category has many sub categories, but every subcategory has one parent category.