fixed FirstOrCreate not handled error when table is not exists (#5367)
* fixed FirstOrCreate not handled error when table is not exists * delete useless part
This commit is contained in:
		
							parent
							
								
									7e13b03bd4
								
							
						
					
					
						commit
						dc1ae394f3
					
				| @ -351,9 +351,9 @@ func (db *DB) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *DB) { | |||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			return tx.Model(dest).Updates(assigns) | 			return tx.Model(dest).Updates(assigns) | ||||||
| 		} else { |  | ||||||
| 			tx.Error = result.Error |  | ||||||
| 		} | 		} | ||||||
|  | 	} else { | ||||||
|  | 		tx.Error = result.Error | ||||||
| 	} | 	} | ||||||
| 	return tx | 	return tx | ||||||
| } | } | ||||||
|  | |||||||
| @ -476,6 +476,13 @@ func TestOmitWithCreate(t *testing.T) { | |||||||
| 	CheckUser(t, result2, user2) | 	CheckUser(t, result2, user2) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func TestFirstOrCreateNotExistsTable(t *testing.T) { | ||||||
|  | 	company := Company{Name: "first_or_create_if_not_exists_table"} | ||||||
|  | 	if err := DB.Table("not_exists").FirstOrCreate(&company).Error; err == nil { | ||||||
|  | 		t.Errorf("not exists table, but err is nil") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func TestFirstOrCreateWithPrimaryKey(t *testing.T) { | func TestFirstOrCreateWithPrimaryKey(t *testing.T) { | ||||||
| 	company := Company{ID: 100, Name: "company100_with_primarykey"} | 	company := Company{ID: 100, Name: "company100_with_primarykey"} | ||||||
| 	DB.FirstOrCreate(&company) | 	DB.FirstOrCreate(&company) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 t-inagaki@hum_op
						t-inagaki@hum_op