我有一个属于会议的活动表。事件hasAndBelongsToMany组,细分,区域和区域。目前,该页面显示所有具有至少1个组,区段,区域和区域的事件,它们链接到用户也链接到该组。我在事件表中添加了一个字段,filtered_by_area,它检查事件是否应仅显示给某些区域/区域或每个人。我需要更改查找,以便显示的事件是filtered_by_area为0的事件,或者事件是否与用户链接到相同的区域/区域。但我似乎无法让它显示未经过滤的事件。这是我的代码:
$conditions = array(
'conditions' => array(
'Meeting.id' => $id,
array(
'OR' => array(
array("Event.filtered_by_area" => 0),
array("AreasEvent.area_id IN ('$areas')",
"EventsRegion.region_id IN ('$regions')")
))
),
'joins' => array(
array(
'table' => 'events',
'alias' => 'Event',
'type' => 'INNER',
'conditions' => array(
'Meeting.id = Event.meeting_id'
)
),
array(
'table' => 'areas_events',
'alias' => 'AreasEvent',
'type' => 'LEFT',
'conditions' => array(
'Event.id = AreasEvent.event_id',
)
),
array(
'table' => 'areas',
'alias' => 'Area',
'type' => 'LEFT',
'conditions' => array(
'Area.id = AreasEvent.area_id',
)
),
array(
'table' => 'events_regions',
'alias' => 'EventsRegion',
'type' => 'LEFT',
'conditions' => array(
'Event.id = EventsRegion.event_id',
)
),
array(
'table' => 'regions',
'alias' => 'Region',
'type' => 'LEFT',
'conditions' => array(
'Region.id = EventsRegion.region_id',
)
)
),
'contain' => array(
'Event.Segment',
'Event.Asset' => array(
'Image',
'Document',
'VimeoVideo',
'Link'
),
'Event.Group' => array(
'conditions' => array(
'Group.name' => $this->group_name
)
),
'Event.Area' => array(),
'Event.Region' => array()
)
);
if (!$this->Meeting->exists()) {
throw new NotFoundException(__('Invalid meeting'));
}
$conditions['contain']['Event.Segment'] = array(
'conditions' => array(
'Segment.id' => $segments
)
);
$conditions['contain']['Event.Area'] = array(
'conditions' => array(
'Area.id' => $areas
)
);
$conditions['contain']['Event.Region'] = array(
'conditions' => array(
'Region.id' => $regions
)
);
if (isset($dates[$day])) {
$conditions['contain']['Event'] = array(
'conditions' => array(
'date_format(Event.start, "%Y-%m-%d")' => $dates[$day]
),
'order' => 'Event.start asc'
);
}
$meeting = $this->Meeting->find('first', $conditions);
任何帮助?
答案 0 :(得分:0)
这里:
'或'=>阵列( 数组(“Event.filtered_by_area”=> 0), array(“AreasEvent.area_id IN('$ areas')”, “EventsRegion.region_id IN('$ regions')”) ))
删除它,并改为这样:
'包含'=>阵列( '模式'=>阵列( '状态'=> $条件) )
答案 1 :(得分:0)
下面:
array(
'OR' => array(
array("Event.filtered_by_area" => 0),
array("AreasEvent.area_id IN ('$areas')",
"EventsRegion.region_id IN ('$regions')")
))
)
删除包装'OR'的数组。它会是这样的:
'conditions' => array(
'Meeting.id' => $id,
'OR' => array(
"Event.filtered_by_area" => 0,
'AND' => array(
"AreasEvent.area_id" => $areas,
"EventsRegion.region_id" => $regions
)
))
)
编辑:更正了IN
子句。如果$areas
和$regions
是数组,那么Cake会自动对查询执行IN
语句
编辑2:更正了OR
编辑3:第三次修改= _ =已添加AND