I got these tables:
- Tag - contains the tag names and id (Tag_ID, tag)
- TagReview - linking table between tags and reviews (Review_ID, Tag_ID)
- Review - holds reviews. (Review_ID, content, ...)
Currently i have made an insertions when review is added or edited. In my Tag table class extends from Zend_DB_Table... Insertion worked for some cases but then failed with sql error " SQLSTATE[23000]: Integrity constraint violation: 1452"
public function insertTags($reviewId, $tagList) {
$reviewTag = new Application_Model_DbTable_ReviewTag;
$tags = explode(self::SEPERATE, $tagList);
foreach ($tags as $tag) {
$tag = trim($tag);
$tagRow = $this->fetchRow(array('tag = ?' => $tag));
if ($tagRow == null) {
$tagId = $this->insert(array(
'tag' => trim($tag)
));
$reviewTag->insert(array(
'Tag_ID' => $tagId,
'Review_ID' => $reviewId,
));
}
}
}