如何为这个表生成一个到多个实体使用doctrine生成器

时间:2016-06-20 12:33:03

标签: php sql doctrine

DROP TABLE IF EXISTS `address`;
CREATE TABLE `address` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customer_id` int(11) DEFAULT NULL,
  `region_code` varchar(255)  DEFAULT NULL,
  `district` varchar(255)  NOT NULL,
  `address` varchar(255)  NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL ON UPDATE NOW(),
  PRIMARY KEY (`id`),
  KEY `IDX_B97FF0589395C3F3` (`customer_id`),
  CONSTRAINT `FK_B97FF0589395C3F3` FOREIGN KEY (`customer_id`) REFERENCES    `customer` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `shipping_address_id` int(11) DEFAULT NULL,
  `email` varchar(255)  NOT NULL,
  `mobile` varchar(255)  DEFAULT NULL,
  `name` varchar(255)  DEFAULT NULL,
  `birthday` datetime DEFAULT NULL,
  `gender` varchar(1)  NOT NULL DEFAULT 'u',
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL ON UPDATE NOW(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `UNIQ_7E82D5E64D4CFF2B` (`address_id`),
  CONSTRAINT `FK_7E82D5E64D4CFF2B` FOREIGN KEY (`shipping_address_id`) REFERENCES    `address` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8;

一个客户有一个默认送货地址,一个地址连接到一个客户。

致命错误:消息'Doctrine \ ORM \ Mapping \ MappingException',消息'属性'客户“在”App \ Model \ Address“已经声明,但它已经声明了 st在第381行的D:\ wamp64 \ www \ app \ vendor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Mapping \ MappingException.php中仅宣布一次

Doctrine \ ORM \ Mapping \ MappingException:“App \ Model \ Address”中的属性“customer”已经声明,但必须在D:\ wamp64 \ www \ app \ v中声明一次 第381行的endor \ doctrine \ orm \ lib \ Doctrine \ ORM \ Mapping \ MappingException.php

Call Stack:
    0.0010     276728   1. {main}() D:\wamp64\www\app\entities_generator.php:0
    0.9090    9239824   2. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() D:\wamp64\www\app\entities_generator.php:166
    0.9090    9249648   3. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() D:\wamp64\www\app\vendor\doctrine\common\lib\Doctr
ine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php:115
    0.9120    9269408   4. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() D:\wamp64\www\app\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Ma
pping\AbstractClassMetadataFactory.php:225
    0.9120    9269680   5. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() D:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\O
RM\Mapping\ClassMetadataFactory.php:78
    0.9260   10011288   6. Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() D:\wamp64\www\app\vendor\doctrine\common\lib\Doctrine\Common\Persistence\
Mapping\AbstractClassMetadataFactory.php:332
    0.9260   10011968   7. Doctrine\ORM\Mapping\Driver\DatabaseDriver->loadMetadataForClass() D:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\Cla
ssMetadataFactory.php:151
    0.9280   10024816   8. Doctrine\ORM\Mapping\Driver\DatabaseDriver->buildToOneAssociationMappings() D:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Ma
pping\Driver\DatabaseDriver.php:188
    0.9280   10034064   9. Doctrine\ORM\Mapping\ClassMetadataInfo->mapOneToMany() D:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\Driver\Database
Driver.php:535
    0.9280   10036640  10. Doctrine\ORM\Mapping\ClassMetadataInfo->_storeAssociationMapping() D:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\Cla
ssMetadataInfo.php:2568
    0.9280   10036640  11. Doctrine\ORM\Mapping\ClassMetadataInfo->assertFieldNotMapped() D:\wamp64\www\app\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMe
tadataInfo.php:2617

对此有任何想法?或者你能告诉我如何设计它以使其更清晰。

感谢提前。

0 个答案:

没有答案