Details
-
Type:
Sub-task
-
Status:
Resolved
-
Priority:
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.
Fixed.