Merge pull request #1001 from stroborobo/assoc-error

association: dont execute Append/Replace/Delete if Error already present
This commit is contained in:
Jinzhu 2016-05-09 22:47:58 +08:00
commit 57c72125b3
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 // Append append new associations for many2many, has_many, replace current association for has_one, belongs_to
func (association *Association) Append(values ...interface{}) *Association { func (association *Association) Append(values ...interface{}) *Association {
if association.Error != nil {
return association
}
if relationship := association.field.Relationship; relationship.Kind == "has_one" { if relationship := association.field.Relationship; relationship.Kind == "has_one" {
return association.Replace(values...) return association.Replace(values...)
} }
@ -30,6 +34,10 @@ func (association *Association) Append(values ...interface{}) *Association {
// Replace replace current associations with new one // Replace replace current associations with new one
func (association *Association) Replace(values ...interface{}) *Association { func (association *Association) Replace(values ...interface{}) *Association {
if association.Error != nil {
return association
}
var ( var (
relationship = association.field.Relationship relationship = association.field.Relationship
scope = association.scope 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 // Delete remove relationship between source & passed arguments, but won't delete those arguments
func (association *Association) Delete(values ...interface{}) *Association { func (association *Association) Delete(values ...interface{}) *Association {
if association.Error != nil {
return association
}
var ( var (
relationship = association.field.Relationship relationship = association.field.Relationship
scope = association.scope scope = association.scope