Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
efd30bdb
Commit
efd30bdb
authored
Nov 19, 2015
by
gobenon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update orm_querym2m.go
parent
01aa1085
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
21 deletions
+18
-21
orm_querym2m.go
orm/orm_querym2m.go
+18
-21
No files found.
orm/orm_querym2m.go
View file @
efd30bdb
...
...
@@ -44,14 +44,19 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
dbase
:=
orm
.
alias
.
DbBaser
var
models
[]
interface
{}
last_md_col_name
:=
mi
.
fields
.
dbcols
[
len
(
mi
.
fields
.
dbcols
)
-
1
]
last_md
:=
mds
[
len
(
mds
)
-
1
]
var
v3
interface
{}
var
names
[]
string
var
values
[]
interface
{}
if
reflect
.
Indirect
(
reflect
.
ValueOf
(
last_md
))
.
Kind
()
!=
reflect
.
Struct
{
v3
=
(
last_md
)
mds
=
mds
[
:
len
(
mds
)
-
1
]
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
{
val
:=
reflect
.
ValueOf
(
md
)
...
...
@@ -71,15 +76,10 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
if
exist
==
false
{
panic
(
ErrMissPK
)
}
if
v3
!=
nil
{
names
=
[]
string
{
mfi
.
column
,
rfi
.
column
,
last_md_col_name
}
values
=
make
([]
interface
{},
0
,
len
(
models
)
*
3
)
}
else
{
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
{
ind
:=
reflect
.
Indirect
(
reflect
.
ValueOf
(
md
))
...
...
@@ -92,17 +92,14 @@ func (o *queryM2M) Add(mds ...interface{}) (int64, error) {
panic
(
ErrMissPK
)
}
}
if
v3
==
nil
{
values
=
append
(
values
,
v1
,
v2
)
}
else
{
values
=
append
(
values
,
v1
,
v2
,
v3
)
}
values
=
append
(
values
,
v1
,
v2
)
}
names
=
append
(
names
,
other_names
...
)
values
=
append
(
values
,
other_values
...
)
return
dbase
.
InsertValue
(
orm
.
db
,
mi
,
true
,
names
,
values
)
}
// remove models following the origin model relationship
func
(
o
*
queryM2M
)
Remove
(
mds
...
interface
{})
(
int64
,
error
)
{
fi
:=
o
.
fi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment