Model:
表与表之间的关系:hasOne 一对一( $fields, $referenceModel, $referencedFields : 当前表中的字段, 对应关系模型, 对应关系模型中表的字字段 )
hasMany 一对多 ( $fields, $referenceModel, $referencedFields : 当前表中的字段, 对应关系模型, 对应关系模型中表的字字段 )
hasManyToMany 多对多
belongsTo 多对一( 属于 ) ( $fields, $referenceModel, $referencedFields : 当前表中的字段, 对应关系模型, 对应关系模型中表的字字段 )
如项目中存在命名空间 则 要在对应的关系中添加alias参数 array( 'alias' => 'namespace' )
例:多对一
$this->belongsTo('company_id', 'App\Models\ErpCompanys', 'id', ['alias' => 'ErpCompanys']);取得关联表中name信息的phalcon代码:
public function userCarAction(){ if($this->request->isPost()){ $this->view->disable(); $info = ErpCompanyCar::findFirst(); $name = $value->ErpCompanys->name; } } 官方文档地址: https://docs.phalconphp.com/zh/latest/reference/model-relationships.html#relationships-between-models