Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. /** @MongoDBDocument */
  2. class Users {
  3.  
  4. /** @MongoDBReferenceMany(targetDocument="Posts", mappedBy="user") */
  5. private $posts;
  6.  
  7. }
  8.  
  9. /** @MongoDBDocument */
  10. class Posts {
  11.  
  12. /** @MongoDBId */
  13. private $wallPostId;
  14.  
  15. /** @MongoDBReferenceOne(targetDocument="Users", inversedBy="posts") */
  16. private $user;
  17.  
  18. /** @MongoDBReferenceMany(targetDocument="Comments", mappedBy="post") */
  19. private $comments;
  20.  
  21. /** @MongoDBString */
  22. private $content;
  23.  
  24. }
  25.  
  26. /** @MongoDBDocument */
  27. class Comments {
  28.  
  29. /** @MongoDBId */
  30. private $commentId;
  31.  
  32. /** @MongoDBReferenceOne(targetDocument="Posts", inversedBy="comments") */
  33. private $post;
  34.  
  35. /** @MongoDBString */
  36. private $content;
  37.  
  38. }
  39.  
  40. $post = $wallPostsAction->getWallPostById("5051d2a1e71a382c1b000000");
  41. $output = "";
  42. $output .= "Wall post content: " . $post->getContent() . "<br>";
  43. // $comment = new Comments();
  44. // $comment->setContent("Nice topic!");
  45. // $comment->setPost($post);
  46. // $this->dm->persist($comment);
  47. // $this->dm->flush();
  48.  
  49. echo count($post->getComments());
  50. foreach($post->getComments() as $comment){
  51. $output .= " comment: " . $comment->getComment() . "<br>";
  52. }
  53.  
  54. {
  55. "_id": ObjectId("---"),
  56. "post"?: {
  57. "$ref": "Posts",
  58. "$id": ObjectId("---"),
  59. "$db": "db"
  60. },
  61. "content": "Nice topic!"
  62. }
  63.  
  64. ->field('comments')->prime(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement