I know there is a lot of questions with this specific problem and there are examples in the official documentation. But I could not find out what I am doing wrong.
I have two Model with a HABTM relation, but apparently it is not saving anything in the join and final table. These are my tables, models and array I am trying to save.
Tables:
champions table:
CREATE TABLE `champions` (
`id` int(11) unsigned NOT NULL,
`key` varchar(50) DEFAULT NULL,
.
.
.
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
champions_tags table:
CREATE TABLE `champions_tags` (
`id` int(11) NOT NULL,
`champion_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
tags table:
CREATE TABLE `tags` (
`id` int(11) NOT NULL,
`type` varchar(50) DEFAULT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Models:
Champion.php
public $hasAndBelongsToMany = array(
'Tag' => array(
'foreignKey' => 'champion_id',
'associationForeignKey' => 'tag_id',
'unique' => 'keepExisting'
)
);
Tag.php
public $hasAndBelongsToMany = array(
'Tag' => array(
'foreignKey' => 'tag_id',
'associationForeignKey' => 'champion_id',
'unique' => 'keepExisting'
)
);
Finally this is the info I am trying to save and spread to tags table
Array
(
[Champion] => Array
(
.
.
.
[Tag] => Array
(
[0] => Array
(
[id] => 2660
[type] => Fighter
)
[1] => Array
(
[id] => 2661
[type] => Tank
)
)
)
)