dsvd407787736 2015-05-04 12:07
浏览 126

Phalcon模型中的一对一关系不返回对象

I have two models in Phalcon .I am getting the model object of the first model using the Placon Model::find(). The problem is I cannot get model object which has an one to one relation with the first model.

I have tried everthing given in Phalcon tutorial.

Gave hasone in first Model on initialize

 public function initialize()
 {
     $this->hasOne("emp_id", "Employee", "emp_id");
 }

Where emp_id is the primary key of Employee table and Foreign key in Salary table, which is my second model.

  • 写回答

1条回答 默认 最新

  • doudouwd2017 2015-05-04 12:25
    关注

    For that you have to specify the relation between 2 models, and how those two models are related. To get one-to-one relation object you can use hasOne relation or hasMany for many-to-many relations.

      $this->hasOne('emp_id', '(path to your model)', 'emp_id', array(
                    'alias' => 'employeeId',
                    'reusable' => true
                ));
    

    Ex: if you have a Employee object and you need access the one-to-one related objects you must use Employee.employeeId to get the related object.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用