【发布时间】:2017-07-21 12:55:52
【问题描述】:
我如何在这里使用 cakephp 2X 模型 hasone 或其他关联概念来执行查找查询。
在我的 Schinfo.php 模型中是
class Schinfo extends AppModel {
public $tablePrefix = 'sko_';
public $hasOne = [
'State' => [
'className' => 'Masterlocation',
'foreignKey' => 'master_locid'
],
'City' => [
'className' => 'Masterlocation',
'foreignKey' => 'master_locid'
],
'Area' => [
'className' => 'Masterlocation',
'foreignKey' => 'master_locid'
]
];
}
通过以上我得到了
SELECT
`Schinfo`.`skool_id`,
`Schinfo`.`skool_code`,
`Schinfo`.`skool_name`,
`Schinfo`.`skool_addr`,
`Schinfo`.`master_state_id`,
`Schinfo`.`master_city_id`,
`Schinfo`.`master_area_id`,
`Schinfo`.`skool_pin`,
`Schinfo`.`skool_board`,
`Schinfo`.`skool_type_id`,
`Schinfo`.`skool_affilated_to`,
`Schinfo`.`skool_affilated_no`,
`Schinfo`.`skool_contact_no`,
`Schinfo`.`skool_mailid`,
`Schinfo`.`skool_website`,
`Schinfo`.`skool_logo`,
`Schinfo`.`skool_delete`,
`State`.`master_locid`,
`State`.`master_parentid`,
`State`.`master_locname`,
`State`.`is_checked`,
`City`.`master_locid`,
`City`.`master_parentid`,
`City`.`master_locname`,
`City`.`is_checked`,
`Area`.`master_locid`,
`Area`.`master_parentid`,
`Area`.`master_locname`,
`Area`.`is_checked`
FROM
`skoolata`.`sko_schinfos` AS `Schinfo`
LEFT JOIN
`skoolata`.`sko_masterlocations` AS `State`
ON (`State`.`master_locid` = `Schinfo`.`id`)
LEFT JOIN
`skoolata`.`sko_masterlocations` AS `City`
ON (`City`.`master_locid` = `Schinfo`.`id`)
LEFT JOIN
`skoolata`.`sko_masterlocations` AS `Area`
ON (`Area`.`master_locid` = `Schinfo`.`id`)
WHERE
1 = 1
现在我需要改变
LEFT JOIN
skoolata.sko_masterlocations AS State
ON (State.master_locid = Schinfo.id)
LEFT JOIN
skoolata.sko_masterlocations AS City
ON (City.master_locid = Schinfo.id)
LEFT JOIN
skoolata.sko_masterlocations AS Area
ON (Area.master_locid = Schinfo.id)
到
LEFT JOIN
skoolata.sko_masterlocations AS State
ON (State.master_locid = Schinfo.master_state_id)
LEFT JOIN
skoolata.sko_masterlocations AS City
ON (City.master_locid = Schinfo.master_city_id)
LEFT JOIN
skoolata.sko_masterlocations AS Area
ON (Area.master_locid = Schinfo.master_area_id)
得到我想要的输出
【问题讨论】:
标签: mysql cakephp cakephp-2.0 cakephp-2.9