Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-1322: Cannot persist entity with Bidirectional-ManyToOne associations #1937

Closed
doctrinebot opened this issue Aug 6, 2011 · 6 comments
Closed
Assignees
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user apoy2k:

For the following entites:

https://gist.github.com/1129392

When I create a new "Play", using existing User and Room entities and trying to persist them

$play = new Play();
$play->setRoom($room);
$play->setUser($user);
$em->persist($play);

I get the following error:
#1452 - Cannot add or update a child row: a foreign key constraint fails (play, CONSTRAINT play*ibfk_1 FOREIGN KEY (user*id) REFERENCES User (id))

The executed query by Doctrine is

INSERT INTO Play (user_id, room_id) VALUES (?, ?) ({"1":1,"2":32}) [] []

But obviously, this doesn't work. It seems, that the entity manager tries to execute the statement as follows

INSERT INTO Play (user*id ,room*id) VALUES ('1', '32')

which is of course wrong. It should be

INSERT INTO Play (user*id ,room*id) VALUES (1, 32)

@doctrinebot
Copy link
Author

Comment created by apoy2k:

Corrected statements

@doctrinebot
Copy link
Author

Comment created by @beberlei:

The problem is not the how the values are inserted. A foreign key constraint fails, i.e. there is no corresponding User with id 32 in the User table, that is why you cannot insert that row.

@doctrinebot
Copy link
Author

Comment created by apoy2k:

SHOW CREATE TABLE Play;

CREATE TABLE play (
id int(11) NOT NULL AUTO_INCREMENT,
user_id int(11) DEFAULT NULL,
room_id int(11) DEFAULT NULL,
PRIMARY KEY (id),
KEY IDX*FEBB7184A76ED395 (user*id),
KEY IDX*FEBB718454177093 (room*id),
CONSTRAINT play*ibfk_1 FOREIGN KEY (user*id) REFERENCES User (id),
CONSTRAINT play*ibfk_2 FOREIGN KEY (room*id) REFERENCES Room (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

@doctrinebot
Copy link
Author

Comment created by @beberlei:

MySQL 5.5 and InnoDB bug on MacOSX

@doctrinebot
Copy link
Author

Issue was closed with resolution "Invalid"

@doctrinebot
Copy link
Author

Comment created by @beberlei:

See http://bugs.mysql.com/bug.php?id=60309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants