mirror of https://github.com/go-gorm/gorm.git
Add ErrPrimaryKeyRequired if schema has no primary key defined
This commit is contained in:
parent
435bf70865
commit
5e72cd9a2b
|
@ -178,10 +178,15 @@ func (db *DB) FindInBatches(dest interface{}, batchSize int, fc func(tx *DB, bat
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
resultsValue := reflect.Indirect(reflect.ValueOf(dest))
|
resultsValue := reflect.Indirect(reflect.ValueOf(dest))
|
||||||
|
if result.Statement.Schema.PrioritizedPrimaryField == nil {
|
||||||
|
tx.AddError(ErrPrimaryKeyRequired)
|
||||||
|
break
|
||||||
|
} else {
|
||||||
primaryValue, _ := result.Statement.Schema.PrioritizedPrimaryField.ValueOf(resultsValue.Index(resultsValue.Len() - 1))
|
primaryValue, _ := result.Statement.Schema.PrioritizedPrimaryField.ValueOf(resultsValue.Index(resultsValue.Len() - 1))
|
||||||
queryDB = tx.Clauses(clause.Gt{Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey}, Value: primaryValue})
|
queryDB = tx.Clauses(clause.Gt{Column: clause.Column{Table: clause.CurrentTable, Name: clause.PrimaryKey}, Value: primaryValue})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tx.RowsAffected = rowsAffected
|
tx.RowsAffected = rowsAffected
|
||||||
return tx
|
return tx
|
||||||
|
|
Loading…
Reference in New Issue