添加虚拟字段后发出查看列表 - cakePHP

时间:2022-10-20 16:25:20

I have a page that lists all the employees working in the company. It's been working fine all the time until I added virtual fields to the Users Model.

我有一个页面列出了在公司工作的所有员工。在我向用户模型添加虚拟字段之前,它一直运行良好。

Now it's giving me the following error:

现在它给了我以下错误:

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'HrEmployee.name'
in 'field list'

SQL Query: SELECT `User`.`id`, `User`.`username`, `User`.`password`,
`User`.`hr_employee_id`, `User`.`group_id`, `User`.`created`, `User`.`modified`,
(CONCAT(`HrEmployee`.`name`, " ", `HrEmployee`.`surname`, " (",
`HrEmployee`.`jobTitle`, ")")) AS `User__fullname` FROM `intraweb_db`.`users`
AS `User` WHERE `User`.`hr_employee_id` = (182)

I am new to cakePHP and as such have been trying to solve the issue. However, I am struggling. Can anyone tell me what I'm doing wrong?

我是cakePHP的新手,因此一直试图解决这个问题。但是,我在挣扎。谁能告诉我我做错了什么?

2 个解决方案

#1


0  

Assuming HrEmployee is another table here;

假设HrEmployee是另一张桌子;

SELECT 
    u.id, u.username, u.password,
    u.hr_employee_id, u.group_id, u.created, u.modified,
    (
        CONCAT(HrEmployee.name, " ", HrEmployee.surname, " (", HrEmployee.jobTitle, ")")
    ) AS u__fullname 
FROM intraweb_db.users AS u 
# need to join HrEmployee via related field with users
JOIN HrEmployee ON (HrEmployee.RELATED_FIELD = u.RELATED_FIELD)
WHERE u.hr_employee_id = (182)

#2


0  

Ok so I fixed it by just removing the Users reference under $hasmany. We don't need it to call that page, so it's all fine.

好的,所以我通过删除$ hasmany下的Users引用来修复它。我们不需要它来调用那个页面,所以一切都很好。

It works now.

它现在有效。

#1


0  

Assuming HrEmployee is another table here;

假设HrEmployee是另一张桌子;

SELECT 
    u.id, u.username, u.password,
    u.hr_employee_id, u.group_id, u.created, u.modified,
    (
        CONCAT(HrEmployee.name, " ", HrEmployee.surname, " (", HrEmployee.jobTitle, ")")
    ) AS u__fullname 
FROM intraweb_db.users AS u 
# need to join HrEmployee via related field with users
JOIN HrEmployee ON (HrEmployee.RELATED_FIELD = u.RELATED_FIELD)
WHERE u.hr_employee_id = (182)

#2


0  

Ok so I fixed it by just removing the Users reference under $hasmany. We don't need it to call that page, so it's all fine.

好的,所以我通过删除$ hasmany下的Users引用来修复它。我们不需要它来调用那个页面,所以一切都很好。

It works now.

它现在有效。