mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 03:01:28 +00:00
Merge pull request #1451 from gobenon/master
fix issue 1438 opened by Ayelet Regev
This commit is contained in:
commit
2c94d9eab2
@ -44,7 +44,20 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
dbase := orm.alias.DbBaser
|
dbase := orm.alias.DbBaser
|
||||||
|
|
||||||
var models []interface{}
|
var models []interface{}
|
||||||
|
var other_values []interface{}
|
||||||
|
var other_names []string
|
||||||
|
|
||||||
|
for _, colname := range mi.fields.dbcols {
|
||||||
|
if colname != mfi.column && colname != rfi.column && colname != fi.mi.fields.pk.column {
|
||||||
|
other_names = append(other_names, colname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, md := range mds {
|
||||||
|
if reflect.Indirect(reflect.ValueOf(md)).Kind() != reflect.Struct && i > 0 {
|
||||||
|
other_values = append(other_values, md)
|
||||||
|
mds = append(mds[:i], mds[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, md := range mds {
|
for _, md := range mds {
|
||||||
val := reflect.ValueOf(md)
|
val := reflect.ValueOf(md)
|
||||||
if val.Kind() == reflect.Slice || val.Kind() == reflect.Array {
|
if val.Kind() == reflect.Slice || val.Kind() == reflect.Array {
|
||||||
@ -67,11 +80,9 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
names := []string{mfi.column, rfi.column}
|
names := []string{mfi.column, rfi.column}
|
||||||
|
|
||||||
values := make([]interface{}, 0, len(models)*2)
|
values := make([]interface{}, 0, len(models)*2)
|
||||||
|
|
||||||
for _, md := range models {
|
for _, md := range models {
|
||||||
|
|
||||||
ind := reflect.Indirect(reflect.ValueOf(md))
|
ind := reflect.Indirect(reflect.ValueOf(md))
|
||||||
|
|
||||||
var v2 interface{}
|
var v2 interface{}
|
||||||
if ind.Kind() != reflect.Struct {
|
if ind.Kind() != reflect.Struct {
|
||||||
v2 = ind.Interface()
|
v2 = ind.Interface()
|
||||||
@ -81,11 +92,11 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
panic(ErrMissPK)
|
panic(ErrMissPK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
values = append(values, v1, v2)
|
values = append(values, v1, v2)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
names = append(names, other_names...)
|
||||||
|
values = append(values, other_values...)
|
||||||
return dbase.InsertValue(orm.db, mi, true, names, values)
|
return dbase.InsertValue(orm.db, mi, true, names, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user