我正在构建一个关系系统,我的数据库中有3个表:
机会有一个关系id为foreignKey,一个人也有一个relation_id。
我以这种方式链接了我的表格:
有机会:
$this->belongsTo('Relations', [
'className' => 'Relations',
'foreignKey' => 'relation_id',
'joinType' => 'LEFT',
]);
人:
$this->belongsTo('Relations', [
'className' => 'Relations',
'foreignKey' => 'relation_id',
'joinType' => 'LEFT',
]);
关系:
$this->hasMany('Opportunities');
$this->hasMany('Persons');
当我添加新机会时,Cakephp会同时建立新关系,但不会创建此人。
当我调试patchEntity时,我得到了结果:
object(Cake\ORM\Entity) {
'statusname' => 'Openstaand',
'title' => 'XX',
'budget' => (float) 123,
'type' => 'nieuw',
'relation_id' => (int) 56,
'relation' => object(App\Model\Entity\Relation) {
'name' => 'XX',
'person' => [
'salutation' => 'Dhr.'
],
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'name' => true,
'person' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Relations'
},
'person' => [
'firstname' => 'XX',
'insertion' => 'XXX',
'surname' => 'XXXX',
'phone' => 'XXXX',
'email' => 'XXXX@a.be'
],
'status_id' => (int) 13,
'chance' => (int) 0,
'source' => '',
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'statusname' => true,
'title' => true,
'budget' => true,
'type' => true,
'relation_id' => true,
'relation' => true,
'person' => true,
'status_id' => true,
'chance' => true,
'source' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Opportunities'
}
我的表单的人员部分设置如下:
<section class="form-group--left">
<span class="global-label"><?= __("Bedrijf"); ?></span>
<section class="control-group">
<?= $this->Form->input('relation.name', ['class' => 'text-field', 'label' => false]); ?>
</section>
</section>
<section class="form-group--left">
<span class="global-label"><?= __('Lead'); ?></span>
<section class="control-group">
<?= $this->Form->input('person.salutation', [
'label' => __('Aanhef'),
'empty' => false,
'options' => [['value' => "Dhr.", 'text' => __("Dhr.")], ['value' => "Mevr.", 'text' => __("Mevr.")]],
'class' => 'text-field'
]); ?>
</section>
<section class="control-group">
<?= $this->Form->input('person.firstname', ['class' => 'text-field', 'label' => __("Voornaam")]); ?>
</section>
<section class="control-group">
<?= $this->Form->input('person.insertion', ['class' => 'text-field', 'label' => __("Tussenvoegsel")]); ?>
</section>
<section class="control-group">
<?= $this->Form->input('person.surname', ['class' => 'text-field', 'label' => __("Achternaam")]); ?>
</section>
</section>
<section class="form-group--left">
<span class="global-label"><?= __("Contact"); ?></span>
<section class="control-group">
<?= $this->Form->input('person.phone', ['class' => 'text-field', 'label' => __("Telefoon")]); ?>
</section>
<section class="control-group">
<?= $this->Form->input('person.email', ['class' => 'text-field', 'label' => __("E-mailadres")]); ?>
</section>
</section>
我也尝试使用this信息来解决我的问题,但在示例中,所有表都与产品编号相关联,并且我没有机会人员的链接。
谁能看到我做错了什么?