func (o *Group) Save(db *periwinkle.Tx) { if o.Subscriptions != nil { var oldSubscriptions []Subscription db.Model(o).Related(&oldSubscriptions) for _, oldsub := range oldSubscriptions { match := false for _, newsub := range o.Subscriptions { if newsub.AddressID == oldsub.AddressID { match = true break } } if !match { var o UserAddress db.First(&o, "id = ?", oldsub.AddressID) if o.Medium != "noop" && o.Medium != "admin" { if err := db.Where("address_id = ? AND group_id = ?", oldsub.AddressID, oldsub.GroupID).Delete(Subscription{}).Error; err != nil { dbError(err) } } } } } if err := db.Save(o).Error; err != nil { dbError(err) } }
func (usr *User) Save(db *periwinkle.Tx) { usr.ID = strings.ToLower(usr.ID) if usr.Addresses != nil { var oldAddresses []UserAddress db.Model(usr).Related(&oldAddresses) deleteAddressIDs := []int64{} for o := range oldAddresses { oldAddr := &oldAddresses[o] match := false for n := range usr.Addresses { newAddr := &usr.Addresses[n] if newAddr.Medium == oldAddr.Medium && newAddr.Address == oldAddr.Address { newAddr.ID = oldAddr.ID match = true } } if !match && oldAddr.Medium != "noop" && oldAddr.Medium != "admin" { deleteAddressIDs = append(deleteAddressIDs, oldAddr.ID) } } if err := db.Save(usr).Error; err != nil { dbError(err) } if len(deleteAddressIDs) > 0 { if err := db.Where("id IN (?)", deleteAddressIDs).Delete(UserAddress{}).Error; err != nil { dbError(err) } } } else { if err := db.Save(usr).Error; err != nil { dbError(err) } } }
func (o *ShortURL) Save(db *periwinkle.Tx) { if err := db.Save(o).Error; err != nil { dbError(err) } }
func (o *TwilioSMSMessage) Save(db *periwinkle.Tx) { if err := db.Save(o).Error; err != nil { dbError(err) } }
func (o *Captcha) Save(db *periwinkle.Tx) { if err := db.Save(o).Error; err != nil { dbError(err) } }
func (o *Session) Save(db *periwinkle.Tx) { if err := db.Save(o).Error; err != nil { dbError(err) } }