我想要用cakephp3插入数据,但这是不对的。数据插入在50%时是可以的。我没有错误,那就是返回。
class SeancesTable extends Table
{
public function initialize(array $config)
{
//$this->hasMany('Exercices');
$this->hasMany('Series');
$this->belongsToMany('Exercices');
$this->addBehavior('TimesTamp');
}
}
class SeriesTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('series');
$this->displayField('id');
$this->primaryKey('id');
$this->belongsTo('Seances');
//$this->hasOne('Seances');
}
public function add(){
$requestData = [
'Seances' =>[
'commentaire' => 'test cake 33',
'date_seance' => '2016-02-27',
'user_id' => 1,
'Series' => [
['nb_rep' => 17, 'charge' => 520, 'exercice_id'=>1],
['nb_rep' => 27, 'charge' => 600]
]
]
];
$seance = $this->Seances->newEntity($requestData,[
'associated' => ['Series']
]);
$this->Seances->save($seance);
}在我的数据库中,数据透视是插入的,而不是序列数据。我该怎么做?
谢谢,为我的英语道歉!!
发布于 2016-03-10 17:58:07
像下面的那样修改代码
$requestData = [
'commentaire' => 'test cake 33',
'date_seance' => '2016-02-27',
'user_id' => 1,
'Series' => [
['nb_rep' => 17, 'charge' => 520, 'exercice_id'=>1],
['nb_rep' => 27, 'charge' => 600]
]
];
$seance = $this->Seances->newEntity($requestData,[
'associated' => ['Series']
]);
$this->Seances->save($seance);在保存hasMany关联时,ORM期望在关联名称的复数、突出显示的版本上有一组实体。去读更多..。Cookbook > Saving Data > Saving hasMay Associations
https://stackoverflow.com/questions/35831922
复制相似问题