保存したいモデルにこの関連付けがあります:
$this->belongsToMany('Tags', [
'className' => 'Tags',
'joinTable' => 'tags_associations',
'foreignKey' => 'foreign_key',
'targetForeignKey' => 'tag_id'
]);
同じだが異なる値tags_associations
を持つ関連するテーブル 2 レコードに保存したい。これは一例ですTags.id
_joinData
object(Companies\Model\Entity\Company) {
'id' => (int) 765,
'tags' => [
(int) 0 => object(Cake\ORM\Entity) {
'id' => (int) 2,
'tag_category_id' => (int) 1,
'level' => (int) 1,
'parent_id' => (int) 1,
'lft' => (int) 2,
'rght' => (int) 135,
'tag_name' => 'Abbigliamento',
'slug' => 'abbigliamento',
'description' => null,
'created' => object(Cake\I18n\Time) {
'time' => '2015-10-04T17:56:02+0200',
'timezone' => 'Europe/Rome',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-10-05T10:03:53+0200',
'timezone' => 'Europe/Rome',
'fixedNowTime' => false
},
'_joinData' => object(Cake\ORM\Entity) {
'model' => 'Companies',
'tag_group_id' => (int) 2,
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'model' => true,
'tag_group_id' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'TagsAssociations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'_joinData' => true
],
'[original]' => [
'_joinData' => object(Cake\ORM\Entity) {
'model' => 'Companies',
'tag_group_id' => (int) 1,
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'model' => true,
'tag_group_id' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'TagsAssociations'
}
],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Tags'
},
(int) 1 => object(Cake\ORM\Entity) {
'id' => (int) 2,
'tag_category_id' => (int) 1,
'level' => (int) 1,
'parent_id' => (int) 1,
'lft' => (int) 2,
'rght' => (int) 135,
'tag_name' => 'Abbigliamento',
'slug' => 'abbigliamento',
'description' => null,
'created' => object(Cake\I18n\Time) {
'time' => '2015-10-04T17:56:02+0200',
'timezone' => 'Europe/Rome',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-10-05T10:03:53+0200',
'timezone' => 'Europe/Rome',
'fixedNowTime' => false
},
'_joinData' => object(Cake\ORM\Entity) {
'model' => 'Companies',
'tag_group_id' => (int) 2,
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'model' => true,
'tag_group_id' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'TagsAssociations'
},
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'_joinData' => true
],
'[original]' => [
'_joinData' => object(Cake\ORM\Entity) {
'model' => 'Companies',
'tag_group_id' => (int) 1,
'[new]' => true,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'model' => true,
'tag_group_id' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'TagsAssociations'
}
],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Tags'
}
],
}
私の例では、2 番目のエンティティのみが tags_association テーブルに保持されます。