dongmaonao0505 2016-02-28 19:47
浏览 47
已采纳

学说,如何离开加入未生成的实体?

I have rights:

CREATE TABLE `rights` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL DEFAULT '',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `U_name` (`name`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

and profiles:

CREATE TABLE `profile` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL DEFAULT '',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `U_name` (`name`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

I want to connect profiles to rights and also profiles to profiles:

CREATE TABLE `profile_profile` (
    `profile_id1` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    `profile_id2` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`profile_id1`, `profile_id2`),
    INDEX `I_profile_id2` (`profile_id2`),
    CONSTRAINT `FK_profile_profile-profile-1` FOREIGN KEY (`profile_id1`) REFERENCES `profile` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT `FK_profile_profile-profile-2` FOREIGN KEY (`profile_id2`) REFERENCES `profile` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

CREATE TABLE `profile_right` (
    `profile_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    `right_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`profile_id`, `right_id`),
    INDEX `I_right_id` (`right_id`),
    CONSTRAINT `FK_profile_right-profile` FOREIGN KEY (`profile_id`) REFERENCES `profile` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT `FK_profile_right-rights` FOREIGN KEY (`right_id`) REFERENCES `rights` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

a better overview:enter image description here

so I generate entities:

php apps/doctrine.php dev orm:generate-entities libs/ --no-backup --extend="\Doctrine\Entity\BaseEntity"

here come the problems. The Profile and Rights entities gets created, while Profile_rights and Profile_profile not. How to use them then?

  • 写回答

2条回答 默认 最新

  • dsam70528 2016-02-28 21:23
    关注

    In doctrine, join tables are not represented by an Entity.

    You can find a @ORM\ManyToMany in your entities, with a @ORM\JoinTable and all informations about your associations.
    This is the representation of your join table(s), use getters and setters like said by @Richard to access them.

    Get more informations in the Associations mapping (to see all kind of associations) and Working with associations (to learn how work with them) chapters of the documentation.

    Hope you have a good experience with doctrine.

    EDIT

    After look more at your UML, at least one of your associations doesn't need a many-to-many (As said by the first answer), but if they really have join tables in SQL, and you imported them by reverse engineering, they will surely be exactly as they are in SQL (a many-to-many with join table).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要