Add a new fild in models TPResource ID and replace primary key with PK and set tenant after ID

This commit is contained in:
TeoV
2017-09-15 16:21:32 +03:00
parent fc66da3b63
commit 0f288af170
11 changed files with 61 additions and 65 deletions

View File

@@ -565,7 +565,7 @@ func (self *SQLStorage) SetTPResources(rls []*utils.TPResource) error {
tx := self.db.Begin()
for _, rl := range rls {
// Remove previous
if err := tx.Where(&TpResource{Tpid: rl.TPid, Tag: rl.ID}).Delete(TpResource{}).Error; err != nil {
if err := tx.Where(&TpResource{Tpid: rl.TPid, ID: rl.ID}).Delete(TpResource{}).Error; err != nil {
tx.Rollback()
return err
}
@@ -1542,7 +1542,7 @@ func (self *SQLStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, er
var rls TpResources
q := self.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("tag = ?", id)
q = q.Where("id = ?", id)
}
if err := q.Find(&rls).Error; err != nil {
return nil, err