Created
February 25, 2016 22:22
-
-
Save jtallant/0b84abe6f670cede25a3 to your computer and use it in GitHub Desktop.
Doctrine Foreign Key Management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Post | |
{ | |
public function addComment(Comment $comment) | |
{ | |
$this->comments->add($comment); | |
$comment->setPost($this); | |
} | |
} | |
$post = new Post; | |
$post->addComment($comment); | |
$em->persist($post); | |
$em->flush(); | |
# Comment now has FK | |
# Keeping entity relationships in sync is pretty easy. | |
# An even easier way to do it is to add cascade={"persist"} to the annotation. | |
# Then you don't have to do $comment->setPost($post); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment