我有一个文件模式,以及多(目前3)不同的其他型号(条,工作,事件),其都可以有文件,存储在文件模式.
问题是,当我产生通过CLI工具表(./doctrine集结全重装),我得到这个错误信息:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot
add or update a child row: a foreign key constraint fails
(`my_database/articles`, CONSTRAINT `articles_id_files_target_id`
FOREIGN KEY (`id`) REFERENCES `files` (`target_id`))
Run Code Online (Sandbox Code Playgroud)
文件定义为(在此模型中定义的关系没有定义):
columns:
id:
primary: true
autoincrement: true
type: integer(4)
target_id: integer(4)
filename: string(255)
[...]
Run Code Online (Sandbox Code Playgroud)
所有4个模型都有这个关系定义:
relations:
Files:
type: many
class: File
local: id
foreign: target_id
Run Code Online (Sandbox Code Playgroud)
这是Doctrine生成的Php-Code(BaseFile.php):
public function setUp()
{
parent::setUp();
$this->hasOne('Publication', array(
'local' => 'target_id',
'foreign' => 'id'));
$this->hasOne('Event', array(
'local' => 'target_id',
'foreign' => 'id'));
$this->hasOne('Article', array(
'local' => 'target_id',
'foreign' => 'id'));
$this->hasOne('Job', array(
'local' => 'target_id',
'foreign' => 'id'));
}
Run Code Online (Sandbox Code Playgroud)
我理解为什么会发生这种情况(不能为多个表设置约束),但不知道如何在没有多个文件表或关联表的情况下解决这个问题.
有没有办法告诉Doctrine它不应该在File模型中创建关系?
有什么好主意吗?
如果需要,请尝试,
关系:
Files:
type: many
class: File
local: target_id
foreign: id
Files2:
type: many
class: File
local: id
foreign: id
Run Code Online (Sandbox Code Playgroud)