2015-12-19 29 views

回答

1

應答位晚了,但我們希望它能幫助別人。 Phalcon提供了令人敬畏的查詢生成器功能。你可以在這裏閱讀更多:https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Query_Builder.html

,這裏是樣品連接查詢:

$result = $this->modelsManager->createBuilder() 
    ->columns(array('main.*', 'locations.*')) 
    ->from(array('main' => 'Models\Objects')) 
    ->leftJoin('Models\ObjectLocations', 'locations.foreign_key = main.id', 'locations') 
    ->where('main.active = 1') 
    ->getQuery()->execute(); 

這將返回兩個對象,如果查詢成功,你選擇從表中的所有字段(*):

$result->main 
$result->locations 

好東西是那些對象允許你使用所有模型方法。例如

$result->locations->getDistanceBlabla()