Fix Column Order Bug #5
1 changed files with 12 additions and 2 deletions
|
@ -82,7 +82,13 @@ func deleteOneToOneConflictsBeforeMerge(tx boil.Executor, conflict conflictingUn
|
|||
|
||||
func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingUniqueKey, primaryID uint64, secondaryID uint64) error {
|
||||
conflictingColumns := strmangle.SetComplement(conflict.columns, []string{conflict.objectIdColumn})
|
||||
|
||||
var objectIDIndex int
|
||||
for i, column := range conflict.columns {
|
||||
if column == conflict.objectIdColumn {
|
||||
objectIDIndex = i
|
||||
break
|
||||
woops..I thought I did that...like literally was thinking it and never added it lol. woops..I thought I did that...like literally was thinking it and never added it lol.
|
||||
}
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"SELECT %s FROM %s WHERE %s IN (%s) GROUP BY %s HAVING count(distinct %s) > 1",
|
||||
strings.Join(conflictingColumns, ","), conflict.table, conflict.objectIdColumn,
|
||||
|
@ -137,7 +143,7 @@ func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingU
|
|||
//There could be multiple conflicting rows between ObjectIDs. In the SELECT query we grab each row and their column
|
||||
// keys to be deleted here in a loop.
|
||||
for _, rowToDelete := range rowsToRemove {
|
||||
rowToDelete = append(rowToDelete, secondaryID)
|
||||
rowToDelete = insert(rowToDelete, objectIDIndex, secondaryID)
|
||||
_, err = tx.Exec(query, rowToDelete...)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
|
@ -146,6 +152,10 @@ func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingU
|
|||
return nil
|
||||
}
|
||||
|
||||
func insert(slice []interface{}, index int, value interface{}) []interface{} {
|
||||
return append(slice[:index], append([]interface{}{value}, slice[index:]...)...)
|
||||
}
|
||||
|
||||
func checkMerge(tx boil.Executor, foreignKeys []foreignKey) error {
|
||||
uniqueColumns := []interface{}{}
|
||||
uniqueColumnNames := map[string]bool{}
|
||||
|
|
Loading…
Reference in a new issue
you can
break
after this