Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      I'm currently playing around with DDC-117. I came across a general
      problem which occurs with relations.

      Given the following two classes, should a
      @OneToOne/@OneToMany/@ManyToMany relation consider a composite ID or is
      that not planned with DDC-117?

      In the past, we assumed that an object is identified unique with an @Id
      column. However, if we support composite keys, an object needs to be
      identified by two or more columns, which we need to take into
      consideration when building queries and foreign keys. Is that correct?

      /**
       * @Entity
       */
      
      class Document {
      	/**
      	 * @Id
      	 * @Column(type="integer")
      	 * @GeneratedValue(strategy="AUTO")
      	 */
      	private $id;
      
      	/**
      	 * @Id
      	 * @Column(type="integer")
      	 */
      	private $version;
      
      	/**
      	 * @ManyToOne(targetEntity="Content")
      	 * Enter description here ...
      	 * @var unknown_type
      	 */
      	private $content;
      }
      
      /**
       * @Entity
       */
      class Content {
      	/**
      	 * @Id
      	 * @Column(type="integer")
      	 * @GeneratedValue(strategy="AUTO")
      	 */
      	private $id;
      
      	/**
      	 * @Id
      	 * @Column(type="integer")
      	 */
      	private $version;
      
      	/**
      	 * @ManyToOne(targetEntity="Document")
      	 */
      
      	private $document;
      }
      

      I know this might become a bit tricky, because $content refers to a
      single instance of Content, but we actually need two columns to identify
      it. That's how it looks if generated with Doctrine2 (DDC-117):

      mysql> describe Document;
      +------------+---------+------+-----+---------+-------+
      | Field      | Type    | Null | Key | Default | Extra |
      +------------+---------+------+-----+---------+-------+
      | id         | int(11) | NO   | PRI | NULL    |       |
      | version    | int(11) | NO   | PRI | NULL    |       |
      | content_id | int(11) | YES  | MUL | NULL    |       |
      +------------+---------+------+-----+---------+-------+
      
      mysql> describe Content;
      +-------------+---------+------+-----+---------+-------+
      | Field       | Type    | Null | Key | Default | Extra |
      +-------------+---------+------+-----+---------+-------+
      | id          | int(11) | NO   | PRI | NULL    |       |
      | version     | int(11) | NO   | PRI | NULL    |       |
      | document_id | int(11) | YES  | MUL | NULL    |       |
      +-------------+---------+------+-----+---------+-------+
      

      However, to make my example work, the tables would need to look the
      following:

      mysql> describe Content;
      +------------------+---------+------+-----+---------+-------+
      | Field            | Type    | Null | Key | Default | Extra |
      +------------------+---------+------+-----+---------+-------+
      | id               | int(11) | NO   | PRI | NULL    |       |
      | version          | int(11) | NO   | PRI | NULL    |       |
      | document_id      | int(11) | YES  | MUL | NULL    |       |
      | document_version | int(11) | YES  |     | NULL    |       |
      +------------------+---------+------+-----+---------+-------+
      
      mysql> describe Document;
      +-----------------+---------+------+-----+---------+-------+
      | Field           | Type    | Null | Key | Default | Extra |
      +-----------------+---------+------+-----+---------+-------+
      | id              | int(11) | NO   | PRI | NULL    |       |
      | version         | int(11) | NO   | PRI | NULL    |       |
      | content_id      | int(11) | YES  | MUL | NULL    |       |
      | content_version | int(11) | YES  |     | NULL    |       |
      +-----------------+---------+------+-----+---------+-------+
      

      It would be nice if we could discuss this one, as I feel it is important for an ORM.

        Activity

        Timo A. Hummel created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Parent DDC-117 [ 10344 ]
        Issue Type New Feature [ 2 ] Sub-task [ 5 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.1 [ 10022 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 12121 ] jira-feedback [ 14647 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 14647 ] jira-feedback2 [ 16511 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16511 ] jira-feedback3 [ 18764 ]

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Timo A. Hummel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: