Guest User

Untitled

a guest
Jul 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2. namespace JoModel;
  3.  
  4. /**
  5. * @Entity
  6. * @InheritanceType("SINGLE_TABLE")
  7. * @DiscriminatorColumn(name="resource_type", type="string")
  8. * @DiscriminatorMap({"article" = "JoModelArticleArticleVote", "comment" = "JoModelArticleCommentVote"})
  9. */
  10. class Vote
  11. {
  12. /**
  13. * @Id
  14. * @Column(type="integer")
  15. * @GeneratedValue(strategy="AUTO")
  16. */
  17. protected $id;
  18.  
  19. /**
  20. * @ManyToOne(targetEntity="JoModelUserUser")
  21. */
  22. protected $user;
  23.  
  24.  
  25. /**
  26. * @Column(type="integer")
  27. */
  28. protected $weight;
  29.  
  30. public function setWeight($weight)
  31. {
  32. $this->weight = $weight;
  33.  
  34. return $this;
  35. }
  36.  
  37. public function getWeight()
  38. {
  39. return $this->weight;
  40. }
  41. }
  42.  
  43. <?php
  44. namespace JoModelArticle;
  45. use JoModel;
  46. /**
  47. * @Entity
  48. */
  49.  
  50. class CommentVote extends ModelVote
  51. {
  52. /**
  53. * @ManyToOne(targetEntity="Comment")
  54. */
  55. protected $comment;
  56.  
  57. public function setComment(Comment $comment)
  58. {
  59. $this->comment = $comment;
  60.  
  61. return $this;
  62. }
  63.  
  64. public function getComment()
  65. {
  66. return $this->comment;
  67. }
  68. }
  69.  
  70. CREATE TABLE Vote (
  71. id INT AUTO_INCREMENT NOT NULL,
  72. user_id INT DEFAULT NULL,
  73. article_id INT DEFAULT NULL,
  74. comment_id INT DEFAULT NULL,
  75. weight INT NOT NULL,
  76. resource_type VARCHAR(255) NOT NULL,
  77. INDEX IDX_FA222A5AA76ED395 (user_id),
  78. INDEX IDX_FA222A5A62922701 (article_id),
  79. INDEX IDX_FA222A5AF8697D13 (comment_id),
  80. PRIMARY KEY(id)
  81. ) ENGINE = InnoDB;
  82.  
  83. $commentVote = new CommentVote();
  84. $commentVote->setComment($comment); // $comment instance of Comment
  85. $commentVote->setWeight(1);
  86. $em->persist($commentVote);
  87. $em->flush();
  88.  
  89. Message: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'resource_type' cannot be null
  90.  
  91. resource_type VARCHAR(255) NOT NULL
  92.  
  93. /**
  94. * @Column(type="string", length=255", nullable=true)
  95. */
  96. private $resource_type;
Add Comment
Please, Sign In to add comment