Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6838121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:33:31+00:00 2026-05-26T23:33:31+00:00

SchemaTool is generating unique index for associations that are OneToOne. I believe this is

  • 0

SchemaTool is generating unique index for associations that are OneToOne. I believe this is incorrect.

Section 6.6 of the Associations manual page at Doctrine shows an example of a OneToOne for a Product has one Shipping. This is shown to generate the Product table:

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

However, with the same code for my entity User has one Organisation, my User table SQL is generated as

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

This prevents me adding 2 users with the same Organisation. Not correct.

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

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

Any ideas? I can’t seem to find anything at all about this.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:33:31+00:00Added an answer on May 26, 2026 at 11:33 pm

    If One organisation has Many Users and Many Users have One and only one organisation then it’s not a One-to-One association.

    One-to-One associations have to be unique.

    Your association is ManyToOne on the User side and OneToMany on the organisation side.

    User.php

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

    Organisation.php

    use Doctrine\Common\Collections\ArrayCollection;
    
    /**
     * @OneToMany(targetEntity="User", mappedBy="organisation")
     */
    private $users;
    
    function __construct() {
        $this->users = new ArrayCollection();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must use \Doctrine\Common\Annotations\AnnotationRegistry::registerFile to access the annotation registry in entity files. This part
OK, if anyone can help me with this that would be great, because it
I know that SchemaExport should be my friend. But I am using liquibase and
This is my piece of code.Im getting all the tables names and col names
i use two classes: namespace Test; use Doctrine\ORM\Mapping as ORM; /** *@Table() *@InheritanceType(Joined) *@DiscriminatorMap({baseclass=BaseClass,
How do I validate that all 'signedWhen' xml attributes should not have time zone
I'm doing test unit of my entity: namespace PathtomyBundle\Tests; require_once dirname(__DIR__).'/../../../app/AppKernel.php'; use Doctrine\ORM\Tools\SchemaTool; abstract
I recently asked this question: Expose XML or Objects - thanks all for the
I'm trying to set up my PHPUnit tests with Doctrine 2 ORM. However, I
I have a Sql Server db that was generated by Nhibernate's schema tool and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.