Raise error if using unaddressable value
This commit is contained in:
		
							parent
							
								
									7934223f99
								
							
						
					
					
						commit
						a97a508ec7
					
				@ -61,7 +61,7 @@ func Create(scope *Scope) {
 | 
				
			|||||||
				if scope.Err(err) == nil {
 | 
									if scope.Err(err) == nil {
 | 
				
			||||||
					scope.db.RowsAffected, _ = result.RowsAffected()
 | 
										scope.db.RowsAffected, _ = result.RowsAffected()
 | 
				
			||||||
					if primaryField != nil {
 | 
										if primaryField != nil {
 | 
				
			||||||
						scope.SetColumn(primaryField, id)
 | 
											scope.Err(scope.SetColumn(primaryField, id))
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,7 @@ func SaveBeforeAssociations(scope *Scope) {
 | 
				
			|||||||
				value := field.Field
 | 
									value := field.Field
 | 
				
			||||||
				scope.Err(scope.NewDB().Save(value.Addr().Interface()).Error)
 | 
									scope.Err(scope.NewDB().Save(value.Addr().Interface()).Error)
 | 
				
			||||||
				if relationship.ForeignFieldName != "" {
 | 
									if relationship.ForeignFieldName != "" {
 | 
				
			||||||
					scope.SetColumn(relationship.ForeignFieldName, scope.New(value.Addr().Interface()).PrimaryKeyValue())
 | 
										scope.Err(scope.SetColumn(relationship.ForeignFieldName, scope.New(value.Addr().Interface()).PrimaryKeyValue()))
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -43,11 +43,11 @@ func SaveAfterAssociations(scope *Scope) {
 | 
				
			|||||||
						newScope := newDB.NewScope(elem)
 | 
											newScope := newDB.NewScope(elem)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						if relationship.JoinTable == "" && relationship.ForeignFieldName != "" {
 | 
											if relationship.JoinTable == "" && relationship.ForeignFieldName != "" {
 | 
				
			||||||
							newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
 | 
												scope.Err(newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue()))
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						if relationship.PolymorphicType != "" {
 | 
											if relationship.PolymorphicType != "" {
 | 
				
			||||||
							newScope.SetColumn(relationship.PolymorphicType, scope.TableName())
 | 
												scope.Err(newScope.SetColumn(relationship.PolymorphicType, scope.TableName()))
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						scope.Err(newDB.Save(elem).Error)
 | 
											scope.Err(newDB.Save(elem).Error)
 | 
				
			||||||
@ -77,11 +77,11 @@ func SaveAfterAssociations(scope *Scope) {
 | 
				
			|||||||
					elem := value.Addr().Interface()
 | 
										elem := value.Addr().Interface()
 | 
				
			||||||
					newScope := scope.New(elem)
 | 
										newScope := scope.New(elem)
 | 
				
			||||||
					if relationship.ForeignFieldName != "" {
 | 
										if relationship.ForeignFieldName != "" {
 | 
				
			||||||
						newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
 | 
											scope.Err(newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue()))
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if relationship.PolymorphicType != "" {
 | 
										if relationship.PolymorphicType != "" {
 | 
				
			||||||
						newScope.SetColumn(relationship.PolymorphicType, scope.TableName())
 | 
											scope.Err(newScope.SetColumn(relationship.PolymorphicType, scope.TableName()))
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					scope.Err(scope.NewDB().Save(elem).Error)
 | 
										scope.Err(scope.NewDB().Save(elem).Error)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								field.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								field.go
									
									
									
									
									
								
							@ -18,7 +18,7 @@ func (field *Field) Set(value interface{}) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !field.Field.CanAddr() {
 | 
						if !field.Field.CanAddr() {
 | 
				
			||||||
		return errors.New("field value not addressable")
 | 
							return errors.New("unaddressable value")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if rvalue, ok := value.(reflect.Value); ok {
 | 
						if rvalue, ok := value.(reflect.Value); ok {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user