I'm really newbie at this stuff. The thing is... I have article site. People can rate articles there. If no one rated, I can delete article. But if anyone rated article, I keep getting following error:
PDOException: SQLSTATE[23503]: Foreign key violation: 7 ERROR: update or delete on table "article" violates foreign key constraint "article_rating_item_id_fkey" on table "article_ratings"
DETAIL: Key (id)=(xxxx) is still referenced from table "article_ratings". in /libs/Nette/loader.php:3515 @ http://www.xxxxxx/admin/articleedit/3578?do=deletearticle @@ exception-2014-09-29-18-14-37-b625334b3e569cb7661f1704256874c1.htm
When I check that file, there is followin code:
public function handleDeletearticle($id)
{
$article = $this->context->createArticles()->get($id);
$this->context->createArticles()->where("id", $id)->delete();
$this->flashMessage('Done', 'success');
$this->redirect('Admin:articles');
}
Could you please help me how to fix it? Thank you in advance
EDIT: this is how it looks Articles.php
public function selectArticleWithRating($slug)
{
$article = $this->query("Select article.*, COUNT(rating.id) AS plus, COUNT(rating2.id) AS minus, \"user\".avatar, \"user\".username
FROM article
LEFT JOIN rating AS rating ON rating.item_id=article.id and rating.type='article' and rating.rate=1
LEFT JOIN rating AS rating2 ON rating2.item_id=article.id and rating2.type='article' and rating2.rate=0
LEFT JOIN \"user\" ON \"user\".id=article.user_id
WHERE slug='$slug'
GROUP BY article.id, \"user\".id");
return $article;
}
Shouldn't there be article_ratings
?