我想通过使用 Doctrine 工具进行逆向工程从现有数据库生成实体
/*
* SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `country`
-- ----------------------------
DROP TABLE IF EXISTS `country`;
CREATE TABLE `country` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `provider`
-- ----------------------------
DROP TABLE IF EXISTS `provider`;
CREATE TABLE `provider` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `provider_country`
-- ----------------------------
DROP TABLE IF EXISTS `provider_country`;
CREATE TABLE `provider_country` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`providerId` int(11) unsigned NOT NULL,
`countryId` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_provider_has_id0_idx` (`providerId`),
KEY `fk_user_country_idx` (`countryId`),
CONSTRAINT `fk_rss_has_id` FOREIGN KEY (`providerId`) REFERENCES `provider` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_user_country` FOREIGN KEY (`countryId`) REFERENCES `country` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
SET FOREIGN_KEY_CHECKS=1;
*/
您可以通过执行以下两个命令来要求 Doctrine 导入架构并构建相关的实体类。
1 美元php app/console doctrine:mapping:import AcmeBlogBundle annotation
2 美元php app/console doctrine:generate:entities AcmeBlogBundle
但现在该学说仅在多方“ProviderCountry”表中检测到 ManyToOne 关系
如果我需要添加 OneToMany 关系,我必须通过添加以下注释手动添加注释
在 Provider.php 添加
/**
* @ORM\OneToMany(targetEntity="ProviderCountry", mappedBy="providerId", cascade={"persist"})
*/
private $datas;
在 ProviderCountry.php 添加
/**
* @var Provider
*
* @ORM\ManyToOne(targetEntity="Provider", inversedBy = "datas")
* @ORM\JoinColumn(name="providerId", referencedColumnName="id")
*/
private $userid;
那么如何通过学说命令生成一对多注释