association: dont execute Append/Replace/Delete if Error already present

This commit is contained in:
Björn 2016-05-06 14:10:43 +02:00
parent bf413d67d3
commit f159fa3d74
1 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,10 @@ func (association *Association) Find(value interface{}) *Association {
// Append append new associations for many2many, has_many, replace current association for has_one, belongs_to
func (association *Association) Append(values ...interface{}) *Association {
if association.Error != nil {
return association
}
if relationship := association.field.Relationship; relationship.Kind == "has_one" {
return association.Replace(values...)
}
@ -30,6 +34,10 @@ func (association *Association) Append(values ...interface{}) *Association {
// Replace replace current associations with new one
func (association *Association) Replace(values ...interface{}) *Association {
if association.Error != nil {
return association
}
var (
relationship = association.field.Relationship
scope = association.scope
@ -118,6 +126,10 @@ func (association *Association) Replace(values ...interface{}) *Association {
// Delete remove relationship between source & passed arguments, but won't delete those arguments
func (association *Association) Delete(values ...interface{}) *Association {
if association.Error != nil {
return association
}
var (
relationship = association.field.Relationship
scope = association.scope