I have a NewsModel which extends Zend_Db_Table_Abstract. the news-table consists of: newsid, title, text and creater. creater reffers to a userid of the user-table. User-table consists of userid and username.
Now i want to have the User in the NewsModel. At the moment
At the moment I do this in the model:
$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
->setIntegrityCheck(false);
$select->join('muskelpilot_users',
'muskelpilot_users.userid= muskelpilot_news.creater',
'username');
return $this->fetchAll($select);
Is there any other solution to solve this problem without a method?
I believe RageZ is right in that you can't have a single model that spans multiple tables without using some sort of ORM.
However, you can easily enough have User_Row->getNewsArticles() and News_Row->getUser() methods.
You can specify relationships in your Models, which allow you to do this:
$newsModel = new NewsModel();
$news = $newsModel->find(1); // find a row, returns an instance of Zend_Db_Table_Row
$user = $news->findDependentRowset('User'); // returns instance of Zend_Db_Table_Rowset
Take a look here for more info: http://framework.zend.com/manual/en/zend.db.table.relationships.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.