1 대 다수의 관계가있는 클래스가 있습니다. 이벤트 종류 :간단한 일대 다 관계 cakePHP
var $hasMany = array(
'Event' => array(
'className' => 'Event',
'foreignKey' => 'event_type_initials',
'dependent' => false,
)
);
이벤트 :
var $belongsTo = array(
'EventType' => array(
'className' => 'EventType',
'foreignKey' => 'event_type_initials'
)
);
는 이전의 관계는 event_type_id에 의해,하지만 지금은 initals로 변경되었습니다. 데이터에 액세스하려고 할 때 쿼리에 문제가 발생합니다. 다음 쿼리가 끝나면 왼쪽 조인이
Event
임을 알 수 있습니다.
event_type_initials
=
EventType
.
id
, 이는 의미가 없습니다.
SELECT `Event`.`id`, `Event`.`event_type_initials`, `Event`.`user_id`, `Event`.`details`, `Event`.`start`, `Event`.`hours`, `Event`.`minutes`, `Event`.`all_day`, `Event`.`active`, `Event`.`created`, `Event`.`modified`, `EventType`.`id`, `EventType`.`initials`, `EventType`.`name`, `EventType`.`address`, `EventType`.`email`, `EventType`.`phone`, `EventType`.`person`, `EventType`.`color` FROM `sunshine3`.`events` AS `Event` LEFT JOIN `sunshine3`.`event_types` AS `EventType` ON (**`Event`.`event_type_initials` = `EventType`.`id`**) WHERE `Event`.`id` = 30
어떤 도움도 환영합니다.
왜 이해가 나던 그? 여기서 예상했던 것을 메모해야합니다. – mark
글쎄, 나는 조인 조건이 다음과 같을 것으로 예상했다. Event.event_type_initials = EventType.initials (EventType.id가 아님) –