[eluser]7amza[/eluser]
Hey,
i started using the DMZ library and all goes cute expet i'm encoutring a problem :
i have three tables :
portals : id - title..
pages : id - portal_id - title..
categories : id - portal_id - title ..
the relation between them is like that :
each page and category has one portal .
and each portal have many categories and pages .
so my models is like that:
:
Code:
//Portal.php
class Portal extends DataMapper {
var $table = "portals";
var $has_many = array("category","page");
function __construct($id = NULL)
{
parent::__construct($id);
}
}
//Page.php
class Page extends DataMapper {
var $table = "pages";
var $has_one = array("portal");
var $has_many = array();
function __construct($id = NULL)
{
parent::__construct($id);
}
}
//Category.php
class Category extends DataMapper {
var $table = "categories";
var $has_one = array("portal");
var $has_many = array("article");
function __construct($id = NULL)
{
parent::__construct($id);
}
}
so in controllers when i use this method :
Code:
function cat(){
$category = new category();
$data['categories'] = $category->get_where(array('portal_id'=>'2'));
it works fine and return all categories related to portal 2 .
when i use this method:
Code:
$page = new page();
$data['portal'] = $page->get_where(array('portal_id'=>'2'));
the method don't works fine:
Quote:DataMapper Error: 'page' is not a valid parent relationship for Portal. Are your relationships configured correctly?
and when i try to get all categories and pages related to portal from the portal i can't gets them !
Code:
$portal = new portal(2);
$categories = $portal->category->get();
$pages = $portal->page->get();//Line 21
Quote:Fatal error: Call to a member function get() on a non-object in G:\AppServ\www\test\application\modules\dir\controllers\home.php on line 21
notice : the line 20 works fine alone it gets all categories related to portal 2 .
so what's wrong please?