e5904443 by slene

fix #302

1 parent 4ee6cc30
...@@ -106,9 +106,7 @@ func bootStrap() { ...@@ -106,9 +106,7 @@ func bootStrap() {
106 msg := fmt.Sprintf("field `%s` wrong rel_through value `%s`", fi.fullName, fi.relThrough) 106 msg := fmt.Sprintf("field `%s` wrong rel_through value `%s`", fi.fullName, fi.relThrough)
107 if i := strings.LastIndex(fi.relThrough, "."); i != -1 && len(fi.relThrough) > (i+1) { 107 if i := strings.LastIndex(fi.relThrough, "."); i != -1 && len(fi.relThrough) > (i+1) {
108 pn := fi.relThrough[:i] 108 pn := fi.relThrough[:i]
109 mn := fi.relThrough[i+1:] 109 rmi, ok := modelCache.getByFN(fi.relThrough)
110 tn := snakeString(mn)
111 rmi, ok := modelCache.get(tn)
112 if ok == false || pn != rmi.pkg { 110 if ok == false || pn != rmi.pkg {
113 err = errors.New(msg + " cannot find table") 111 err = errors.New(msg + " cannot find table")
114 goto end 112 goto end
......
...@@ -122,7 +122,7 @@ type Post struct { ...@@ -122,7 +122,7 @@ type Post struct {
122 Content string `orm:"type(text)"` 122 Content string `orm:"type(text)"`
123 Created time.Time `orm:"auto_now_add"` 123 Created time.Time `orm:"auto_now_add"`
124 Updated time.Time `orm:"auto_now"` 124 Updated time.Time `orm:"auto_now"`
125 Tags []*Tag `orm:"rel(m2m)"` 125 Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/orm.PostTags)"`
126 } 126 }
127 127
128 func (u *Post) TableIndex() [][]string { 128 func (u *Post) TableIndex() [][]string {
...@@ -148,6 +148,16 @@ func NewTag() *Tag { ...@@ -148,6 +148,16 @@ func NewTag() *Tag {
148 return obj 148 return obj
149 } 149 }
150 150
151 type PostTags struct {
152 Id int
153 Post *Post `orm:"rel(fk)"`
154 Tag *Tag `orm:"rel(fk)"`
155 }
156
157 func (m *PostTags) TableName() string {
158 return "prefix_post_tags"
159 }
160
151 type Comment struct { 161 type Comment struct {
152 Id int 162 Id int
153 Post *Post `orm:"rel(fk);column(post)"` 163 Post *Post `orm:"rel(fk);column(post)"`
......
...@@ -146,6 +146,7 @@ func TestSyncDb(t *testing.T) { ...@@ -146,6 +146,7 @@ func TestSyncDb(t *testing.T) {
146 RegisterModel(new(Tag)) 146 RegisterModel(new(Tag))
147 RegisterModel(new(Comment)) 147 RegisterModel(new(Comment))
148 RegisterModel(new(UserBig)) 148 RegisterModel(new(UserBig))
149 RegisterModel(new(PostTags))
149 150
150 err := RunSyncdb("default", true, false) 151 err := RunSyncdb("default", true, false)
151 throwFail(t, err) 152 throwFail(t, err)
...@@ -161,6 +162,7 @@ func TestRegisterModels(t *testing.T) { ...@@ -161,6 +162,7 @@ func TestRegisterModels(t *testing.T) {
161 RegisterModel(new(Tag)) 162 RegisterModel(new(Tag))
162 RegisterModel(new(Comment)) 163 RegisterModel(new(Comment))
163 RegisterModel(new(UserBig)) 164 RegisterModel(new(UserBig))
165 RegisterModel(new(PostTags))
164 166
165 BootStrap() 167 BootStrap()
166 168
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!