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
e5904443
Commit
e5904443
authored
Nov 24, 2013
by
slene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #302
parent
4ee6cc30
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
4 deletions
+14
-4
models_boot.go
orm/models_boot.go
+1
-3
models_test.go
orm/models_test.go
+11
-1
orm_test.go
orm/orm_test.go
+2
-0
No files found.
orm/models_boot.go
View file @
e5904443
...
...
@@ -106,9 +106,7 @@ func bootStrap() {
msg
:=
fmt
.
Sprintf
(
"field `%s` wrong rel_through value `%s`"
,
fi
.
fullName
,
fi
.
relThrough
)
if
i
:=
strings
.
LastIndex
(
fi
.
relThrough
,
"."
);
i
!=
-
1
&&
len
(
fi
.
relThrough
)
>
(
i
+
1
)
{
pn
:=
fi
.
relThrough
[
:
i
]
mn
:=
fi
.
relThrough
[
i
+
1
:
]
tn
:=
snakeString
(
mn
)
rmi
,
ok
:=
modelCache
.
get
(
tn
)
rmi
,
ok
:=
modelCache
.
getByFN
(
fi
.
relThrough
)
if
ok
==
false
||
pn
!=
rmi
.
pkg
{
err
=
errors
.
New
(
msg
+
" cannot find table"
)
goto
end
...
...
orm/models_test.go
View file @
e5904443
...
...
@@ -122,7 +122,7 @@ type Post struct {
Content
string
`orm:"type(text)"`
Created
time
.
Time
`orm:"auto_now_add"`
Updated
time
.
Time
`orm:"auto_now"`
Tags
[]
*
Tag
`orm:"rel(m2m)"`
Tags
[]
*
Tag
`orm:"rel(m2m)
;rel_through(github.com/astaxie/beego/orm.PostTags)
"`
}
func
(
u
*
Post
)
TableIndex
()
[][]
string
{
...
...
@@ -148,6 +148,16 @@ func NewTag() *Tag {
return
obj
}
type
PostTags
struct
{
Id
int
Post
*
Post
`orm:"rel(fk)"`
Tag
*
Tag
`orm:"rel(fk)"`
}
func
(
m
*
PostTags
)
TableName
()
string
{
return
"prefix_post_tags"
}
type
Comment
struct
{
Id
int
Post
*
Post
`orm:"rel(fk);column(post)"`
...
...
orm/orm_test.go
View file @
e5904443
...
...
@@ -146,6 +146,7 @@ func TestSyncDb(t *testing.T) {
RegisterModel
(
new
(
Tag
))
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
UserBig
))
RegisterModel
(
new
(
PostTags
))
err
:=
RunSyncdb
(
"default"
,
true
,
false
)
throwFail
(
t
,
err
)
...
...
@@ -161,6 +162,7 @@ func TestRegisterModels(t *testing.T) {
RegisterModel
(
new
(
Tag
))
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
UserBig
))
RegisterModel
(
new
(
PostTags
))
BootStrap
()
...
...
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