Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace JoModel;
- /**
- * @Entity
- * @InheritanceType("SINGLE_TABLE")
- * @DiscriminatorColumn(name="resource_type", type="string")
- * @DiscriminatorMap({"article" = "JoModelArticleArticleVote", "comment" = "JoModelArticleCommentVote"})
- */
- class Vote
- {
- /**
- * @Id
- * @Column(type="integer")
- * @GeneratedValue(strategy="AUTO")
- */
- protected $id;
- /**
- * @ManyToOne(targetEntity="JoModelUserUser")
- */
- protected $user;
- /**
- * @Column(type="integer")
- */
- protected $weight;
- public function setWeight($weight)
- {
- $this->weight = $weight;
- return $this;
- }
- public function getWeight()
- {
- return $this->weight;
- }
- }
- <?php
- namespace JoModelArticle;
- use JoModel;
- /**
- * @Entity
- */
- class CommentVote extends ModelVote
- {
- /**
- * @ManyToOne(targetEntity="Comment")
- */
- protected $comment;
- public function setComment(Comment $comment)
- {
- $this->comment = $comment;
- return $this;
- }
- public function getComment()
- {
- return $this->comment;
- }
- }
- CREATE TABLE Vote (
- id INT AUTO_INCREMENT NOT NULL,
- user_id INT DEFAULT NULL,
- article_id INT DEFAULT NULL,
- comment_id INT DEFAULT NULL,
- weight INT NOT NULL,
- resource_type VARCHAR(255) NOT NULL,
- INDEX IDX_FA222A5AA76ED395 (user_id),
- INDEX IDX_FA222A5A62922701 (article_id),
- INDEX IDX_FA222A5AF8697D13 (comment_id),
- PRIMARY KEY(id)
- ) ENGINE = InnoDB;
- $commentVote = new CommentVote();
- $commentVote->setComment($comment); // $comment instance of Comment
- $commentVote->setWeight(1);
- $em->persist($commentVote);
- $em->flush();
- Message: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'resource_type' cannot be null
- resource_type VARCHAR(255) NOT NULL
- /**
- * @Column(type="string", length=255", nullable=true)
- */
- private $resource_type;
Add Comment
Please, Sign In to add comment