i don´t know what you exactly mean.
The ACTION::CASADE have no effect for me:
here are my db tables:
DROP TABLE IF EXISTS `tags`;
CREATE TABLE IF NOT EXISTS `tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) UNIQUE ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `files`;
CREATE TABLE IF NOT EXISTS `files` (
`id` VARCHAR(36) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`extension` VARCHAR(5) NOT NULL,
`version` INT(11) NOT NULL,
`date` DATE NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE If EXISTS `tags_files`;
CREATE TABLE IF NOT EXISTS `tags_files` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`tag_id` INT(11) NOT NULL,
`file_id` VARCHAR(36) NOT NULL,
PRIMARY KEY (`id`) -- ,
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
Models:
Tags:
public function initialize()
{
$this->hasManytoMany(
'id',
'App\Models\TagsFiles',
'tag_id', 'file_id',
'App\Models\Files',
'id',
array(
'alias' => 'tagsFiles',
'foreignKey' => array(
// 'action' => Relation::ACTION_CASCADE
"message" => "The part cannot be deleted because other robots are using it",
)
)
);
}
TagsFiles;
public function initialize()
{
$this->belongsTo(
'file_id',
'App\Models\Files',
'id',
array(
'alias'=> 'file',
'reusable' => true,
'foreignKey' => [
// 'action' => Relation::ACTION_CASCADE,
'message' => 'file can´t deleted at the moment'
]
)
);
$this->belongsTo(
'tag_id',
'App\Models\Tags',
'id',
array(
'alias'=>'tag',
'foreignKey' => [
'action' => Relation::ACTION_CASCADE,
'message' => 'tag id does not exist or is currenty invalid'
]
)
);
}
Files:
public function initialize()
{
$this->hasManytoMany(
'id',
'App\Models\TagsFiles',
'file_id', 'tag_id',
'App\Models\Tags',
'id',
array(
'alias'=>'tagsFiles',
'foreignKey' => array(
'action' => Relation::ACTION_CASCADE,
)
)
);
}
and the command to delete:
$Files =$this->modelsManager->createBuilder()
->columns('TagsFiles.*')
->from(['TagsFiles'=>'App\Models\TagsFiles'])
->leftJoin('App\Models\Files', 'TagsFiles.file_id = Files.id', 'Files')
->leftJoin('App\Models\Tags', 'TagsFiles.tag_id = Tags.id', 'Tags')
->where('Files.version = :version:', ['version' => '6'] )
->getQuery()
->execute();
$Files->delete();
if execute this he only delete the entry in TagsFiles and not in files too.
Do i missunderstand the Foreign key Action::CASCDE?
Thanks for your advance help