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
7d6c45d4
Commit
7d6c45d4
authored
Sep 06, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add RegisterModelWithSuffix #2140
parent
c697b980
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
+25
-7
models_boot.go
orm/models_boot.go
+25
-7
No files found.
orm/models_boot.go
View file @
7d6c45d4
...
...
@@ -22,8 +22,9 @@ import (
)
// register models.
// prefix means table name prefix.
func
registerModel
(
prefix
string
,
model
interface
{})
{
// PrefixOrSuffix means table name prefix or suffix.
// isPrefix whether the prefix is prefix or suffix
func
registerModel
(
PrefixOrSuffix
string
,
model
interface
{},
isPrefix
bool
)
{
val
:=
reflect
.
ValueOf
(
model
)
typ
:=
reflect
.
Indirect
(
val
)
.
Type
()
...
...
@@ -39,8 +40,12 @@ func registerModel(prefix string, model interface{}) {
table
:=
getTableName
(
val
)
if
prefix
!=
""
{
table
=
prefix
+
table
if
PrefixOrSuffix
!=
""
{
if
isPrefix
{
table
=
PrefixOrSuffix
+
table
}
else
{
table
=
table
+
PrefixOrSuffix
}
}
// models's fullname is pkgpath + struct name
name
:=
getFullName
(
typ
)
...
...
@@ -213,7 +218,6 @@ func bootStrap() {
}
}
}
if
fi
.
reverseFieldInfoTwo
==
nil
{
err
=
fmt
.
Errorf
(
"can not find m2m field for m2m model `%s`, ensure your m2m model defined correct"
,
fi
.
relThroughModelInfo
.
fullName
)
...
...
@@ -297,17 +301,31 @@ end:
// RegisterModel register models
func
RegisterModel
(
models
...
interface
{})
{
if
modelCache
.
done
{
panic
(
fmt
.
Errorf
(
"RegisterModel must be run before BootStrap"
))
}
RegisterModelWithPrefix
(
""
,
models
...
)
}
// RegisterModelWithPrefix register models with a prefix
func
RegisterModelWithPrefix
(
prefix
string
,
models
...
interface
{})
{
if
modelCache
.
done
{
panic
(
fmt
.
Errorf
(
"RegisterModel must be run before BootStrap"
))
panic
(
fmt
.
Errorf
(
"RegisterModelWithPrefix must be run before BootStrap"
))
}
for
_
,
model
:=
range
models
{
registerModel
(
prefix
,
model
,
true
)
}
}
// RegisterModelWithSuffix register models with a suffix
func
RegisterModelWithSuffix
(
suffix
string
,
models
...
interface
{})
{
if
modelCache
.
done
{
panic
(
fmt
.
Errorf
(
"RegisterModelWithSuffix must be run before BootStrap"
))
}
for
_
,
model
:=
range
models
{
registerModel
(
prefix
,
model
)
registerModel
(
suffix
,
model
,
false
)
}
}
...
...
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