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:
//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 :
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:
$page = new page();
$data['portal'] = $page->get_where(array('portal_id'=>'2'));
the method don’t works fine:
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 !
$portal = new portal(2);
$categories = $portal->category->get();
$pages = $portal->page->get();//Line 21
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 . my database structue :
CREATE TABLE
categories(idint(11) NOT NULL auto_increment,
portal_idint(11) default NULL,
titlevarchar(255) NOT NULL,
descriptionvarchar(600) NOT NULL,
slugvarchar(100) NOT NULL,
createddatetime NOT NULL,
updateddatetime NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;CREATE TABLE
pages(idint(11) NOT NULL auto_increment,portal_idint(11) default NULL,titlevarchar(255) NOT NULL,contentlongtext NOT NULL,slugvarchar(100) NOT NULL,createddatetime NOT NULL,updateddatetime NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;CREATE TABLE
portals(idint(11) NOT NULL auto_increment,
titlevarchar(150) NOT NULL,
createddatetime NOT NULL,
updateddatetime NOT NULL,slugvarchar(100) NOT NULL, PRIMARY KEY (id), UNIQUE KEYtitle(title,slug) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
so what's wrong?