actually I'm finding some problems when working with Zend_Db and related
classes.
For example I've noticed that when using the 'dependent row' magic method no
field of the parent class are returned and this is a strange way to work
because when I do a join I need both tables fields ... but maybe I've
misunderstood something.
However, I've also found a way to work and get all the field I need with a
join.
$id = (int)$params["id"];
$pages = new Pages();
$pagesInfo = $pages->info();
$pagesContent = new PagesContent();
$pagesContent = $pagesContent->info();
$select = $pages->select()->setIntegrityCheck(false)
->from(array("a" => $pagesInfo['name']),array('a.*'))
->joinLeft(array("b" => $pagesContent['name']),'b.page_id =
a.page_id')
->where('a.page_id = ?',$id)
->where('b.language_id = ?',1);
$result = $pages->fetchAll($select);
$this->view->result = $result->current();
I will get all the fields I need in both classes and also I can join other
table in a simply way.
The inconvenient is to create a 'info' var for each instanciated model. If
you have named table fields the 'right way' I think you could use the
joinUsing method when joining.
Actually I'm use the config.ini to save tables name so there is no need to
use them when coding. To specify table name when creating a model just add
these lines of code
protected function _setupTableName(){
$config = Zend_Registry::get('config');
$this->_name = $config->table->pages;
parent::_setupTableName();
}
I'm posting this because I've done HOURS of google searching finding few
discussion about this. Also the official documentation is still missing
something.
It will be useful also to know what you think about my solution and if
actually it exists a better one.
Cheers
--
View this message in context: http://www.nabble.com/Fetch-parent-row-automatically-tp18486102p20728826.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论