2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
import "github.com/jinzhu/gorm"
|
|
|
|
|
|
|
|
type PhotoKeyword struct {
|
|
|
|
PhotoID uint `gorm:"primary_key;auto_increment:false"`
|
|
|
|
KeywordID uint `gorm:"primary_key;auto_increment:false;index"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (PhotoKeyword) TableName() string {
|
|
|
|
return "photos_keywords"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPhotoKeyword(photoID, keywordID uint) *PhotoKeyword {
|
|
|
|
result := &PhotoKeyword{
|
|
|
|
PhotoID: photoID,
|
|
|
|
KeywordID: keywordID,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PhotoKeyword) FirstOrCreate(db *gorm.DB) *PhotoKeyword {
|
2019-12-19 09:37:10 +01:00
|
|
|
if err := db.FirstOrCreate(m, "photo_id = ? AND keyword_id = ?", m.PhotoID, m.KeywordID).Error; err != nil {
|
|
|
|
log.Errorf("photo keyword: %s", err)
|
|
|
|
}
|
2019-12-08 15:05:35 +01:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|