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
(id
int(11) NOT NULL auto_increment,
portal_id
int(11) default NULL,
title
varchar(255) NOT NULL,
description
varchar(600) NOT NULL,
slug
varchar(100) NOT NULL,
created
datetime NOT NULL,
updated
datetime NOT NULL, PRIMARY KEY (id
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;CREATE TABLE
pages
(id
int(11) NOT NULL auto_increment,portal_id
int(11) default NULL,title
varchar(255) NOT NULL,content
longtext NOT NULL,slug
varchar(100) NOT NULL,created
datetime NOT NULL,updated
datetime NOT NULL, PRIMARY KEY (id
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;CREATE TABLE
portals
(id
int(11) NOT NULL auto_increment,
title
varchar(150) NOT NULL,
created
datetime NOT NULL,
updated
datetime NOT NULL,slug
varchar(100) NOT NULL, PRIMARY KEY (id
), UNIQUE KEYtitle
(title
,slug
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
so what's wrong?