Doctrine Project

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Doctrine 2 - ORM
  • Doctrine 2 - ORM
  • DDC-117 Allow @Id on @ManyToOne fields
  • DDC-881

DDC-117: Linked Objects with composite key

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Resolved 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

  • All
  • Comments
  • History
  • Activity
  • Source

People

  • Assignee:
    Roman S. Borschel
    Reporter:
    Timo A. Hummel
Vote (0)
Watch (1)

Dates

  • Created:
    18/Nov/10 3:20 AM
    Updated:
    02/Jan/11 6:05 AM
    Resolved:
    02/Jan/11 6:05 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Doctrine Project. Try JIRA - bug tracking software for your team.