有问题的两个模型是项目和事件。
以下是关系:
var $belongsTo = array(
'Project' => array(
'className' => 'Project',
'foreignKey' => 'project_id'
),
var $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => false,
'dependent' => false,
),
问题是,每当我尝试列出所有项目时,只会列出附有事件的项目。我期待着解决这个问题。
这是我得到的查询:
选择
Event
。id
,Event
.project_id
,Event
.user_id
,Event
.date
,Event
.hours
,Event
.minutes
,Event
.xhours
,Event
.xminutes
,Event
.xdetails
,Event
.assignment
,Event
.start_time
,Project
.id
,Project
.name
,Project
.customer_id
,Project
.project_nr
,Project
.address
,Project
.post_nr
,Project
.city
,Project
.company_id
,User
.id
,User
.employee_nr
,User
.name
,User
.surname
,User
.User
.password
,User
.role
,User
.phone
,User
.address
,User
.post_nr
,User
.city
,User
.token_hash
,User
.company_id
从scheduling
。events
如左Event
加入scheduling
。projects
ASProject
ON (Event
.project_id
=Project
.id
) 左连接scheduling
。users
ASUser
ON (Event
.user_id
=User
.id
) 其中 1 = 1 限制 15
上次更新后我得到的查询如下:
选择
Event
。id
,Event
.project_id
,Event
.user_id
,Event
.date
,Event
.hours
,Event
.minutes
,Event
.xhours
,Event
.xminutes
,Event
.xdetails
,Event
.assignment
,Event
.start_time
,Event
.material_id
,Event
.km_drive
,Event
.time_drive
,Event
.finish_time
,Project
.id
,Project
.name
,Project
.customer_id
,Project
.project_nr
,Project
.address
,Project
.post_nr
,Project
.city
,Project
.company_id
,Project
.color
,User
.id
,User
.employee_nr
,User
.name
,User
.surname
,User
.User
.password
,User
.role
,User
.phone
,User
.address
,User
.post_nr
,User
.city
,User
.token_hash
,User
.company_id
,User
.car_id
从scheduling
。events
如左Event
加入scheduling
。projects
ASProject
ON (Event
.project_id
=Project
.id
) 左连接scheduling
。users
ASUser
ON (Event
.user_id
=User
.id
) 其中 1 = 1 限制 20
这是我在尝试列出项目时得到的数组:
array(
(int) 0 => array(
'Event' => array(
'id' => '57',
'project_id' => '13',
'user_id' => '1',
'date' => '2013-08-07',
'hours' => '2',
'minutes' => '35',
'start_time' => '00:00:00',
),
'Project' => array(
'id' => '13',
'name' => 'new project',
'customer_id' => '2',
'project_nr' => '215',
'company_id' => '1',
),
'User' => array(
'password' => '*****',
'id' => '1',
'employee_nr' => null,
'role' => 'manager',
'phone' => '11 12 13 14',
'token_hash' => null,
'company_id' => '1',
'car_id' => null
)
),
(int) 1 => array(
'Event' => array(
'id' => '72',
'project_id' => '13',
'user_id' => '1',
'date' => '2013-08-08',
'hours' => '5',
'minutes' => '35',
'start_time' => '00:00:00',
),
'Project' => array(
'id' => '13',
'name' => 'new project',
'customer_id' => '2',
'project_nr' => '215',
'company_id' => '1',
),
'User' => array(
'password' => '*****',
'id' => '1',
'employee_nr' => null,
'role' => 'manager',
'phone' => '11 12 13 14',
'token_hash' => null,
'company_id' => '1',
'car_id' => null
)
),
所以基本上我得到了包含相关项目而没有相关客户的事件列表。我想要得到的是这样的数组:
(int) 1 => array(
'Project' => array(
'id' => '13',
'name' => 'old project',
'customer_id' => '2',
'project_nr' => '215',
),
'Customer' => array(
'id' => '2',
'project_id' => '13',
'address' => 'abc',
'initials' => 'HUJ',
),
),