简体   繁体   English

Php Phalcon中的模型层次结构-访问子模型时找不到父模型的属性

[英]Model Hierarchy In Php Phalcon - Can't Find Attribute of Parent Model When Accessing Child Model

I am working on Php Phalcon, Xampp server. 我正在使用Phamp Phalcon,Xampp服务器。 My model classes form an heirarchy. 我的模型类构成一个层次结构。

I have a UsersAbstract class which has some generic attributes like Full_Name, Email_ID etc. Then I have derived class UserOfficials which has more attributes like Occupation etc. Then I have a grandchild class (which inherits from UserOfficials) called OfficialDoctor. 我有一个UsersAbstract类,它具有一些泛型属性,例如Full_Name,Email_ID等。然后,我派生了类UserOfficials,它具有了更多的属性,如Occupation等。然后,我有一个孙类(继承自UserOfficials),称为OfficialDoctor。 UsersAbstract class is parent to UserPatients too. UsersAbstract类也是UserPatients的父类。

When I wanted to access UsersAbstract and UserPatients, I used the following code: 当我想访问UsersAbstract和UserPatients时,我使用了以下代码:

$select_patient = "Select "
                            ."UserPatients.Patient_ID, "
                            ."UserPatients.Unique_ID, "
                            ."UsersAbstract.Full_Name, "
                            ."UsersAbstract.Age, "
                            ."UsersAbstract.Gender, "
                            ."UsersAbstract.City, "
                            ."UsersAbstract.Country FROM UserPatients JOIN UsersAbstract WHERE UsersAbstract.Unique_ID = UserPatients.Unique_ID "
                            ."And UsersAbstract.Availablity_Flag = 1";

        $patients = $this->modelsManager->executeQuery($select_patient);
        $this->current_patient = $patients[0];

This worked beautifully. 效果很好。 Now I want to access one attribute from UserOfficials and here is my code: 现在,我想从UserOfficials访问一个属性,这是我的代码:

$id = $user->Unique_ID;
               $select_doctor = "Select UserOfficials.Occupation from UserOfficials WHERE UserOfficials.Unique_ID = :uid:";
               $occ = $this->modelsManager->executeQuery($select_doctor, array("uid" => $id));

This code gives me the following error: 此代码给我以下错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'usersabstract.Occupation' in 'field list'

My question is short - WHY? 我的问题很简短-为什么? I am accessing the table UserOfficials not UsersAbstract. 我正在访问表UserOfficials而不是UsersAbstract。

Note: My tables and corresponding classes are named as follows: 注意:我的表和相应的类的名称如下:

Class -------------- Table

UsersAbstract ------ UsersAbstract

UserOfficials ------ User_Officials

UserPatients ------- User_Patients

I know about the camel case names for corresponding database tables must but if one query works then why doesn't the other? 我知道有关相应数据库表的驼峰案例名称必须知道,但是如果一个查询有效,那么为什么另一个查询不起作用?

I have solved the problem, I had to put single quotes around the name of the column ie 我已经解决了这个问题,我不得不在列名的周围加上单引号,即

$select_doctor = "Select UserOfficials.Occupation from UserOfficials WHERE UserOfficials.Unique_ID = :uid:" ; $select_doctor = "Select UserOfficials.Occupation from UserOfficials WHERE UserOfficials.Unique_ID = :uid:" ;

After this, it gave no more errors. 在此之后,它不再产生任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM