Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 属性为yaml映射的联接表-原则_Php_Mysql_Doctrine Orm - Fatal编程技术网

Php 属性为yaml映射的联接表-原则

Php 属性为yaml映射的联接表-原则,php,mysql,doctrine-orm,Php,Mysql,Doctrine Orm,我有一个可以包含N个用户和可以属于M个列表的用户的列表。联接表有它自己的属性,如DateAdd、dateRemoved等。我将有createList(列表)、createUser(用户)、list.addUserToList(用户)、list.removeUserFromList(用户)等操作。在删除用户时,我希望他也删除表单列表\用户\ tb。在deleteList上,我希望删除仅属于该列表的所有用户。很明显,list_tb和Users_tb与list_user_tb有一对多的关系 我不确定列

我有一个可以包含N个用户和可以属于M个列表的用户的列表。联接表有它自己的属性,如DateAdd、dateRemoved等。我将有createList(列表)、createUser(用户)、list.addUserToList(用户)、list.removeUserFromList(用户)等操作。在删除用户时,我希望他也删除表单列表\用户\ tb。在deleteList上,我希望删除仅属于该列表的所有用户。很明显,list_tb和Users_tb与list_user_tb有一对多的关系

我不确定列表\用户\ tb是否应该与用户和列表建立多对一关系?这只是一个问题,我必须在php或mysql中添加和删除句柄,这将为我解决这个问题

我的问题是什么是yaml理论中的正确映射?当我使用doctor
orm:convert-mapping-yaml./config/yaml--from-database--force
时,它只创建了join-manytomy关系,但正如我所说的,我希望使用附加属性连接表。因此,我删除了一个外键并创建了映射,然后手动将其添加到yaml中

我也读过这两篇文章

这是我到目前为止所拥有的

//用户机顶盒

CREATE TABLE IF NOT EXISTS list_tb (
    list_id               VARCHAR(255) PRIMARY KEY, 
    country               VARCHAR(255) NOT NULL
);

CREATE TABLE IF NOT EXISTS users_tb (           
    id_str          VARCHAR(255) PRIMARY KEY,             
    name            VARCHAR(255) NOT NULL,
    statuses_count  INT(10)      NOT NULL   
);

CREATE TABLE IF NOT EXISTS list_user_tb (
    list_id         VARCHAR(255),
    user_id         VARCHAR(255),
    priority        INT(10)  NOT NULL,
    date_added      DATETIME NOT NULL,
    date_removed    DATETIME NOT NULL
    PRIMARY KEY (list_id, user_id)
);

ALTER TABLE list_user_tb 
    ADD CONSTRAINT fk_list_user_tb_list_tb FOREIGN KEY (list_id) REFERENCES list_tb(list_id);

ALTER TABLE list_user_tb 
    ADD CONSTRAINT fk_list_user_tb_users_tb FOREIGN KEY (user_id) REFERENCES users_tb(id_str);
//ListTb.yml

UsersTb:
    type: entity
    table: users_tb
    id:
        idStr:
            type: string
            nullable: false
            length: 255
            fixed: false
            default: ''
            id: true
            column: id_str
            generator:
                strategy: IDENTITY
    fields:
        name:
            type: string
            nullable: false
            length: 255
            fixed: false
        statusesCount:
            type: integer
            nullable: false
            unsigned: false
            column: statuses_count
    lifecycleCallbacks: {  }
//ListUserTb.yml

ListTb:
    type: entity
    table: list_tb
    id:
        listId:
            type: string
            nullable: false
            length: 255
            fixed: false
            default: ''
            id: true
            column: list_id
            generator:
                strategy: IDENTITY
    fields:
        country:
            type: string
            nullable: false
            length: 255
            fixed: false
    lifecycleCallbacks: {  }

这是答案,在这个链接上做了很好的解释,正如我现在看到的那样,还有额外的复杂性,因为list_id和user_id同时是复合主键和外键。
ListUserTb:
    type: entity
    table: list_user_tb
    indexes:
        IDX_6D2EC7B13DAE168B:
            columns:
                - list_id
    id:
        userId:
            type: string
            nullable: false
            length: 255
            fixed: false
            id: true
            column: user_id
    id:
        idStr:
            type: string
            nullable: false
            length: 255
            fixed: false
            id: true
            column: id_str
            generator:
                strategy: IDENTITY
    fields:
        priority:
            type: integer
            nullable: false
            unsigned: false
        dateAdded:
            type: datetime
            nullable: false
            column: date_added
        dateRemoved:
            type: datetime
            nullable: false
            column: date_removed
    manyToOne:
        list:
            targetEntity: ListTb
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                list_id:
                    referencedColumnName: list_id
            orphanRemoval: false
        user:
            targetEntity: UsersTb
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                id_str:
                    referencedColumnName: id_str
            orphanRemoval: false
    lifecycleCallbacks: {  }