mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:21:02 +00:00
Update orm_querym2m.go
This commit is contained in:
parent
01aa1085e0
commit
efd30bdba7
@ -44,14 +44,19 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
dbase := orm.alias.DbBaser
|
dbase := orm.alias.DbBaser
|
||||||
|
|
||||||
var models []interface{}
|
var models []interface{}
|
||||||
last_md_col_name := mi.fields.dbcols[len(mi.fields.dbcols)-1]
|
var other_values []interface{}
|
||||||
last_md := mds[len(mds)-1]
|
var other_names []string
|
||||||
var v3 interface{}
|
|
||||||
var names []string
|
for _, colname := range mi.fields.dbcols {
|
||||||
var values []interface{}
|
if colname != mfi.column && colname != rfi.column && colname != fi.mi.fields.pk.column {
|
||||||
if reflect.Indirect(reflect.ValueOf(last_md)).Kind() != reflect.Struct {
|
other_names = append(other_names, colname)
|
||||||
v3 = (last_md)
|
}
|
||||||
mds = mds[:len(mds)-1]
|
}
|
||||||
|
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)
|
||||||
@ -71,15 +76,10 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
if exist == false {
|
if exist == false {
|
||||||
panic(ErrMissPK)
|
panic(ErrMissPK)
|
||||||
}
|
}
|
||||||
if v3 != nil {
|
|
||||||
names = []string{mfi.column, rfi.column, last_md_col_name}
|
|
||||||
|
|
||||||
values = make([]interface{}, 0, len(models)*3)
|
names := []string{mfi.column, rfi.column}
|
||||||
} else {
|
|
||||||
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))
|
||||||
@ -92,17 +92,14 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
|
|||||||
panic(ErrMissPK)
|
panic(ErrMissPK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v3 == nil {
|
values = append(values, v1, v2)
|
||||||
values = append(values, v1, v2)
|
|
||||||
} else {
|
|
||||||
values = append(values, v1, v2, v3)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// remove models following the origin model relationship
|
// remove models following the origin model relationship
|
||||||
func (o *queryM2M) Remove(mds ...interface{}) (int64, error) {
|
func (o *queryM2M) Remove(mds ...interface{}) (int64, error) {
|
||||||
fi := o.fi
|
fi := o.fi
|
||||||
|
Loading…
Reference in New Issue
Block a user