开发者

Zend Join Models

I have models of my tables and would like to do a join using a model as opposed to to a table. For example, in开发者_开发知识库stead of:

$select = $this->select()
 ->from(array('p' => 'products'),
   array('product_id', 'product_name'))
 ->join(array('l' => 'line_items'),
   'p.product_id = l.product_id',
 ->limit(20, 10);

where I specify the table names and columns I want to join, can I not use my models?

$select = $this->select()
 ->from(array('p' => 'products'),
   array('product_id', 'product_name'))
 ->join(array('l' => Model_Table1::tableName()),
   'p.product_id = l.product_id',
 ->limit(20, 10);


no ... u cann't join two model ... these are class which can be include .. so u can only use these class in controller or can include in another model too ... according to application or requirement


I don't see why not, if your model has a static variable with the name and a static function to return the variable:

protected static $table = 'dbname';
public static function tableName() {
    return self::$table;
}

Is it worth it though? Is the table name ever going to change?


You must set integrity check is false. Like this

$select = $this->select()
 ->setIntegrityCheck(false)
 ->from(array('p' => 'products'),
   array('product_id', 'product_name'))
 ->join(array('l' => 'line_items'),
   'p.product_id = l.product_id',
 ->limit(20, 10);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜