Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @MongoDBDocument */
- class Users {
- /** @MongoDBReferenceMany(targetDocument="Posts", mappedBy="user") */
- private $posts;
- }
- /** @MongoDBDocument */
- class Posts {
- /** @MongoDBId */
- private $wallPostId;
- /** @MongoDBReferenceOne(targetDocument="Users", inversedBy="posts") */
- private $user;
- /** @MongoDBReferenceMany(targetDocument="Comments", mappedBy="post") */
- private $comments;
- /** @MongoDBString */
- private $content;
- }
- /** @MongoDBDocument */
- class Comments {
- /** @MongoDBId */
- private $commentId;
- /** @MongoDBReferenceOne(targetDocument="Posts", inversedBy="comments") */
- private $post;
- /** @MongoDBString */
- private $content;
- }
- $post = $wallPostsAction->getWallPostById("5051d2a1e71a382c1b000000");
- $output = "";
- $output .= "Wall post content: " . $post->getContent() . "<br>";
- // $comment = new Comments();
- // $comment->setContent("Nice topic!");
- // $comment->setPost($post);
- // $this->dm->persist($comment);
- // $this->dm->flush();
- echo count($post->getComments());
- foreach($post->getComments() as $comment){
- $output .= " comment: " . $comment->getComment() . "<br>";
- }
- {
- "_id": ObjectId("---"),
- "post"?: {
- "$ref": "Posts",
- "$id": ObjectId("---"),
- "$db": "db"
- },
- "content": "Nice topic!"
- }
- ->field('comments')->prime(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement