Skip to content

Commit

Permalink
association: dont execute Append/Replace/Delete if Error already present
Browse files Browse the repository at this point in the history
  • Loading branch information
stroborobo committed May 6, 2016
1 parent bf413d6 commit f159fa3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f159fa3

Please sign in to comment.