Doctrine无法继续记录删除

时间:2017-04-14 12:47:20

标签: php mysql symfony doctrine-orm doctrine

当用户想要删除记录(在我的情况下是语言)时,如果在系统中的任何其他表中引用了记录(语言),我想阻止删除它。

问题是我的案例中的语言(记录)即使在任何其他表中被引用也会被删除。我检查了我在MySQL工作台中的关系,它说在DELETE和ON UPDATE它有RESTRICT动作,但由于某种原因,Doctrine / Symfony允许删除相同的字段。

有人知道问题出在哪里吗?

以下是实体设置:

#include <iostream>
#include <string.h>
#include <fstream>   
#include <sstream>
using namespace std;

int main()
{
    ifstream file("input.csv");
    string line,cell;
    string name[5][20];
    string period[5][8];
    string tname;
    int pos, i = 0;

    while(getline(file, line)) {
        stringstream linestream(line);
        int j = 0;
        while(getline(linestream, cell, ',')) {
            if(j == 0)
                name[i][j] = cell;
            else
                period[i][j - 1] = cell;
            j++;
        }
        i++;
    }

1 个答案:

答案 0 :(得分:0)

您可以在数据库级别强制执行它(这样可以保持整个应用程序的一致性)......

ALTER TABLE `table_name`
ADD CONSTRAINT `constraint_name`
FOREIGN KEY (`column_list`)
REFERENCES `referenced_table` (`referenced_column_list`);