Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Security Level: All
-
Labels:None
Description
Given the following entity definitions, Doctrine does not attempt to manage generated values. For example, in MySQL, it is perfectly possible to create a composite primary key and set auto_increment on one of these. See below the code for issues that occur.
User.php
/**
* @Entity
*/
class User {
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(type="string")
*/
private $name;
/**
* @OneToMany(targetEntity="PhoneNumber",mappedBy="id",cascade={"all"})
*/
private $phoneNumbers;
public function setName ($name) {
$this->name = $name;
}
}
PhoneNumber.php
/**
* @Entity
*/
class PhoneNumber {
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Id
* @ManyToOne(targetEntity="User",cascade={"all"})
*/
private $user;
/**
* @Column(type="string")
*/
private $phonenumber;
public function setUser (User $user) {
$this->user = $user;
}
public function setPhoneNumber ($phoneNumber) {
$this->phonenumber = $phoneNumber;
}
}
Invokation
$albert = new User; $albert->setName("albert"); $em->persist($albert); $phoneAlbert1 = new PhoneNumber(); $phoneAlbert1->setUser($albert); $phoneAlbert1->setPhoneNumber("albert home: 012345"); $em->persist($phoneAlbert1);
The first issue which occurs is that Doctrine does not generate the field "id" within PhoneNumber set to auto_increment.
The second issue which occurs is that Doctrine becomes confused when inserting a new record into PhoneNumber, because of the following INSERT INTO statement:
Insert Statement
INSERT INTO PhoneNumber (user_id, phonenumber) VALUES (?, ?)
array(1) {
[1]=>
string(19) "albert home: 012345"
}
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
I don't think this will ever be possible.