我是CakePHP的新手,我正在制作一个活动日历。事件可以是单日事件或多天,因此我创建了事件表和日期表。保存事件时,日期会按预期保存在日期表中但是event_id字段始终保存为0而不是实际的事件ID。
我认为事件和日期表之间的关系设置正确 这就是我对DatesTable的看法:
$this->table('dates');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Events', [
'foreignKey' => 'event_id'
]);
这是我的活动表:
$this->table('events');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Dates', [
'foreignKey' => 'event_id',
'joinType' => 'INNER'
]);
这是我的EventsController中的代码(WetKit是我们的插件之一):
$event = $this->Events->newEntity();
if ($this->request->is('post')) {
$event = $this->Events->patchEntity($event, $this->request->data, [
'associated' => 'dates'
]);
if ($this->Events->save($event)) {
$this->Flash->success(__('The form has been saved.'));
} else
$this->WetKit->flashError(__('The form could not be saved because error(s) were found.'), $event);
}
如何在Dates表中获取要保存的事件ID?
答案 0 :(得分:0)
A=[3,4,2,1,2,2,2,3,2,3,2,3,5,6,2]
def Sort(x):
count=0
for t in range(len(x)-1):
if x[t]>x[t+1]:
count+=1
m,n=x[t+1],x[t]
x[t+1],x[t]=n,m
if count==0:
return x
else:
Sort(x)
print Sort(A)
方面的关联错误,应该是EventsTable
(hasMany
)关联或1:n
(hasOne
)关联。鉴于你在谈论多天,我认为你正在寻找前者。
另见