table categories with fields: id, name, info, image table categories_subcategs with fields: id, category_id, subcateg_id
<?php class Category extends DataMapper { var $table = "categories"; var $has_many = array( 'subcateg' => array( 'class' => 'category', 'other_field' => 'category' ), 'category' => array( 'other_field' => 'subcateg' ) ); function __construct($id = NULL) { parent::__construct($id); } } ?>
$parentcat = new Category(); $parentcat->name = "temp name"; $parentcat->info = "sdfsdf sdfdsfdsf"; $parentcat->save(); $subcategory = new Category(); $subcategory->name = "sub category name"; $subcategory->info ="sdf dsf dfd"; $subcategory->save(); $parentcat->save_subcateg($subcategory);