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
b6446659
Commit
b6446659
authored
Nov 06, 2013
by
slene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orm set relation column name #259
parent
9492e413
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
models_test.go
orm/models_test.go
+1
-1
models_utils.go
orm/models_utils.go
+6
-3
No files found.
orm/models_test.go
View file @
b6446659
...
@@ -150,7 +150,7 @@ func NewTag() *Tag {
...
@@ -150,7 +150,7 @@ func NewTag() *Tag {
type
Comment
struct
{
type
Comment
struct
{
Id
int
Id
int
Post
*
Post
`orm:"rel(fk)"`
Post
*
Post
`orm:"rel(fk)
;column(post)
"`
Content
string
`orm:"type(text)"`
Content
string
`orm:"type(text)"`
Parent
*
Comment
`orm:"null;rel(fk)"`
Parent
*
Comment
`orm:"null;rel(fk)"`
Created
time
.
Time
`orm:"auto_now_add"`
Created
time
.
Time
`orm:"auto_now_add"`
...
...
orm/models_utils.go
View file @
b6446659
...
@@ -73,13 +73,16 @@ func getTableUnique(val reflect.Value) [][]string {
...
@@ -73,13 +73,16 @@ func getTableUnique(val reflect.Value) [][]string {
}
}
func
getColumnName
(
ft
int
,
addrField
reflect
.
Value
,
sf
reflect
.
StructField
,
col
string
)
string
{
func
getColumnName
(
ft
int
,
addrField
reflect
.
Value
,
sf
reflect
.
StructField
,
col
string
)
string
{
column
:=
strings
.
ToLower
(
col
)
col
=
strings
.
ToLower
(
col
)
if
column
==
""
{
column
:=
col
if
col
==
""
{
column
=
snakeString
(
sf
.
Name
)
column
=
snakeString
(
sf
.
Name
)
}
}
switch
ft
{
switch
ft
{
case
RelForeignKey
,
RelOneToOne
:
case
RelForeignKey
,
RelOneToOne
:
column
=
column
+
"_id"
if
len
(
col
)
==
0
{
column
=
column
+
"_id"
}
case
RelManyToMany
,
RelReverseMany
,
RelReverseOne
:
case
RelManyToMany
,
RelReverseMany
,
RelReverseOne
:
column
=
sf
.
Name
column
=
sf
.
Name
}
}
...
...
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