mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:30:54 +00:00
fix #302
This commit is contained in:
parent
4ee6cc3022
commit
e5904443d9
@ -106,9 +106,7 @@ func bootStrap() {
|
|||||||
msg := fmt.Sprintf("field `%s` wrong rel_through value `%s`", fi.fullName, fi.relThrough)
|
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) {
|
if i := strings.LastIndex(fi.relThrough, "."); i != -1 && len(fi.relThrough) > (i+1) {
|
||||||
pn := fi.relThrough[:i]
|
pn := fi.relThrough[:i]
|
||||||
mn := fi.relThrough[i+1:]
|
rmi, ok := modelCache.getByFN(fi.relThrough)
|
||||||
tn := snakeString(mn)
|
|
||||||
rmi, ok := modelCache.get(tn)
|
|
||||||
if ok == false || pn != rmi.pkg {
|
if ok == false || pn != rmi.pkg {
|
||||||
err = errors.New(msg + " cannot find table")
|
err = errors.New(msg + " cannot find table")
|
||||||
goto end
|
goto end
|
||||||
|
@ -122,7 +122,7 @@ type Post struct {
|
|||||||
Content string `orm:"type(text)"`
|
Content string `orm:"type(text)"`
|
||||||
Created time.Time `orm:"auto_now_add"`
|
Created time.Time `orm:"auto_now_add"`
|
||||||
Updated time.Time `orm:"auto_now"`
|
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 {
|
func (u *Post) TableIndex() [][]string {
|
||||||
@ -148,6 +148,16 @@ func NewTag() *Tag {
|
|||||||
return obj
|
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 {
|
type Comment struct {
|
||||||
Id int
|
Id int
|
||||||
Post *Post `orm:"rel(fk);column(post)"`
|
Post *Post `orm:"rel(fk);column(post)"`
|
||||||
|
@ -146,6 +146,7 @@ func TestSyncDb(t *testing.T) {
|
|||||||
RegisterModel(new(Tag))
|
RegisterModel(new(Tag))
|
||||||
RegisterModel(new(Comment))
|
RegisterModel(new(Comment))
|
||||||
RegisterModel(new(UserBig))
|
RegisterModel(new(UserBig))
|
||||||
|
RegisterModel(new(PostTags))
|
||||||
|
|
||||||
err := RunSyncdb("default", true, false)
|
err := RunSyncdb("default", true, false)
|
||||||
throwFail(t, err)
|
throwFail(t, err)
|
||||||
@ -161,6 +162,7 @@ func TestRegisterModels(t *testing.T) {
|
|||||||
RegisterModel(new(Tag))
|
RegisterModel(new(Tag))
|
||||||
RegisterModel(new(Comment))
|
RegisterModel(new(Comment))
|
||||||
RegisterModel(new(UserBig))
|
RegisterModel(new(UserBig))
|
||||||
|
RegisterModel(new(PostTags))
|
||||||
|
|
||||||
BootStrap()
|
BootStrap()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user