From da0646a67662e2431d0af2750bfffed34bb5a53d Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Fri, 7 Oct 2016 00:03:02 +0200
Subject: [PATCH] Fix db tags

---
 bot/collection.go |  5 +++++
 bot/db.go         | 24 +++++++++++++++++++-----
 site/content.go   |  6 ++++++
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/bot/collection.go b/bot/collection.go
index 5b44615..5597c27 100644
--- a/bot/collection.go
+++ b/bot/collection.go
@@ -43,6 +43,11 @@ func (pbc *PlayBotCollection) InsertPost(post *Post) error {
 			return err
 		}
 
+        pbc.Db.Model(&content).Related(&content.Tags)
+
+        if len(post.Content.Tags) > 0 {
+            content.Tags = append(content.Tags, post.Content.Tags...)
+        }
 		post.Content = &content
 	}
 
diff --git a/bot/db.go b/bot/db.go
index d10c532..c4a76e4 100644
--- a/bot/db.go
+++ b/bot/db.go
@@ -17,9 +17,11 @@ type DbParams struct {
 }
 
 type Db interface {
-	Insert(interface{}) Db
 	Error() error
+	Insert(interface{}) Db
 	First(interface{}) Db
+    Model(interface{}) Db
+    Related(interface{}) Db
 	Where(interface{}) Db
 }
 
@@ -48,22 +50,34 @@ func NewPlayBotDb(dbParams DbParams) (Db, error) {
 	return &PlayBotDb{db}, nil
 }
 
+func (pdb *PlayBotDb) Error() error {
+	return pdb.db.Error
+}
+
 func (pdb *PlayBotDb) Insert(value interface{}) Db {
 	return &PlayBotDb{
 		pdb.db.Create(value),
 	}
 }
 
-func (pdb *PlayBotDb) Error() error {
-	return pdb.db.Error
-}
-
 func (pdb *PlayBotDb) First(value interface{}) Db {
 	return &PlayBotDb{
 		pdb.db.First(value),
 	}
 }
 
+func (pdb *PlayBotDb) Model(value interface{}) Db {
+	return &PlayBotDb{
+		pdb.db.Model(value),
+	}
+}
+
+func (pdb *PlayBotDb) Related(value interface{}) Db {
+	return &PlayBotDb{
+		pdb.db.Related(value),
+	}
+}
+
 func (pdb *PlayBotDb) Where(value interface{}) Db {
 	return &PlayBotDb{
 		pdb.db.Where(value),
diff --git a/site/content.go b/site/content.go
index 3b3829e..a3d20fc 100644
--- a/site/content.go
+++ b/site/content.go
@@ -1,5 +1,9 @@
 package site
 
+import (
+	"log"
+)
+
 type Content struct {
 	Author       string `gorm:"column:sender"`
 	Duration     int
@@ -19,7 +23,9 @@ func (Content) TableName() string {
 }
 
 func (c *Content) AddTags(tags []string) {
+	log.Print(tags)
 	for _, tag := range tags {
 		c.Tags = append(c.Tags, Tag{Tag: tag})
+		log.Print(c.Tags)
 	}
 }
-- 
GitLab