防止在表格中多次插入评论

时间:2017-11-29 14:33:52

标签: php mysql symfony

我正在尝试确保用户在审核后只能查看一次图书。下面是一个示例表结构

评论表

id | userfk  |  bookfk
1  |  45     |   53
2  |  46     |   53  //at this point a book has two reviews from two users
3  |  45     |   53  //attempting to prevent this

从上面的表结构中,你可以看到id为45的用户成功审阅了两次,因此我想将其核实

下面是我的代码尝试,但我无法同时检查两列(userfk和bookfk)

$hasReviewed = $this->getDoctrine()->getRepository('xxxBundle:Reviews')->findOneBy(array('userfk' => $int));
        if (!$hasReviewed) {

        }

请问我该怎样才能确保这个

3  |  45     |   53 
如果表已经添加到表记录中,则

不会在表中重复。

0 个答案:

没有答案