English 中文(简体)
单单单单单单单错吗? 产生一个UNI Request INDEX
原标题:Doctrine OneToOne incorrectly? generating a UNIQUE INDEX

Schema 工具正在为“一对一”协会制定独特的指数。 我认为这不正确。

在Doctrine,协会手册第6.6节显示,“一个产品”有1艘船。 这表明产生了产品表:

CREATE TABLE Product (
    id INT AUTO_INCREMENT NOT NULL,
    shipping_id INT DEFAULT NULL,
    PRIMARY KEY(id)
) ENGINE = InnoDB;

然而,由于我实体用户的同一守则有一个组织,我的用户表是编造的。

CREATE TABLE User (
    id INT AUTO_INCREMENT NOT NULL,
    organisation_id INT DEFAULT NULL,
    UNIQ_3B978F9FA7F43455 (organisation_id),
    PRIMARY KEY(id)
) ENGINE = InnoDB;

这使我无法在同一个组织中增加2个用户。 不正确。

I additinally tried to be verbose with the unique JoinColumn annotation param.

@JoinColumn(name="organisation_id", referencedColumnName="id", unique="false")

任何想法? 我看不到这一点。

增 编

最佳回答

如果一个组织有许多用户,而且许多用户只有一个,只有一个组织,它就不是一个一对一的协会。

一个至一个协会必须具有独特性。

用户方面的“ManyTo One和One ToMany

用户.php

/**
 * @ManyToOne(targetEntity="Organisation")
 */
private $organisation;

Organisation.php

use DoctrineCommonCollectionsArrayCollection;

/**
 * @OneToMany(targetEntity="User", mappedBy="organisation")
 */
private $users;

function __construct() {
    $this->users = new ArrayCollection();
}
问题回答

或许可以采用YML版本,帮助其他人从理论/重罪开始。 我的版本是:

<><>User.orm.yml

manyToOne:
    organisation:
        targetEntity: Organisation
        joinColumn:
            name: organisation_id
            referencedColumnName: id

<>条码>

oneToMany:
    users:
        targetEntity: User
        mappedBy: organisation
        joinColumn:
            name: organisation_id
            referencedColumn: id

希望会有所助益。





相关问题
Zend and static class properties

I m trying to assign a value to a static class property when defining it: namespace Base; abstract class Skeleton { protected static $entityManager = end_Registry::get("EntityManager"); ......

require_once missing doctrine zend framework

I m integrating doctrine with Zend Framework. I ve hit an error thrown from cli. It seems Zend_Application_Bootstrap_Bootstrap does not have a require_once for ...

doctrine: QueryBuilder vs createQuery?

In Doctrine you can create DQL in 2 ways: EntityManager::createQuery: $query = $em->createQuery( SELECT u FROM MyProjectModelUser u WHERE u.id = ?1 ); QueryBuilder: $qb->add( select , u ) ...

热门标签