tags:

views:

49

answers:

2

Please see the code here: http://pastie.org/1092106

When I call the method createPost on Blog, I keep getting an exception, it reads as follows:

At line 474 in lib/Doctrine/ORM/Persisters/BasicEntityPersister.php - Undefined index: id

OH, and also... I regenerate $_SESSION['User'] on each page load, so the object isn't detached from the entity manager or anything like that.

Here are the schemas Doctrine2 is envisioning:

Array (
    [0] => CREATE TABLE Note (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, text LONGTEXT NOT NULL, created DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB
    [1] => CREATE TABLE BlogPost (note_id INT NOT NULL, blog_name VARCHAR(255) NOT NULL, PRIMARY KEY(note_id, blog_name)) ENGINE = InnoDB
    [2] => CREATE TABLE User (email VARCHAR(95) NOT NULL, id INT NOT NULL, password VARCHAR(32) NOT NULL, alias VARCHAR(15) DEFAULT NULL, firstName VARCHAR(20) DEFAULT NULL, lastName VARCHAR(20) DEFAULT NULL, enabled TINYINT(1) NOT NULL, created DATETIME NOT NULL, UNIQUE INDEX User_id_uniq (id), PRIMARY KEY(email)) ENGINE = InnoDB
    [3] => ALTER TABLE Note ADD FOREIGN KEY (user_id) REFERENCES User(id)
    [4] => ALTER TABLE BlogPost ADD FOREIGN KEY (note_id) REFERENCES Note(id)
    [5] => ALTER TABLE BlogPost ADD FOREIGN KEY (blog_name) REFERENCES Blog(name)
)

Hopefully someone can help!

A: 

Are you using annotations?

Rui
Yes. If you check the pastie code, it is all done using annotations.
Omega
A: 

So, upon further inspection, it appears as though adding the following annotation to the $id field on my User class got it working:

* @Id

Perhaps at this point someone could help me understand why my property has to be a unique identifier before it can participate in a relationship?

Omega