From 5612f61a9384e61279cf289faee2fceb667ccb5d Mon Sep 17 00:00:00 2001 From: Artem Nistratov Date: Wed, 8 Jul 2015 17:42:00 +0300 Subject: [PATCH] fix #671 --- orm/models_boot.go | 5 ++++- orm/models_info_f.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/orm/models_boot.go b/orm/models_boot.go index cb44bc05..5232a48d 100644 --- a/orm/models_boot.go +++ b/orm/models_boot.go @@ -269,7 +269,10 @@ func bootStrap() { if found == false { mForC: for _, ffi := range fi.relModelInfo.fields.fieldsByType[RelManyToMany] { - if ffi.relModelInfo == mi { + conditions := fi.relThrough != "" && fi.relThrough == ffi.relThrough || + fi.relTable != "" && fi.relTable == ffi.relTable || + fi.relThrough == "" && fi.relTable == "" + if ffi.relModelInfo == mi && conditions { found = true fi.reverseField = ffi.reverseFieldInfoTwo.name diff --git a/orm/models_info_f.go b/orm/models_info_f.go index 84a0c024..01863aaa 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -223,6 +223,11 @@ checkType: break checkType case "many": fieldType = RelReverseMany + if tv := tags["rel_table"]; tv != "" { + fi.relTable = tv + } else if tv := tags["rel_through"]; tv != "" { + fi.relThrough = tv + } break checkType default: err = fmt.Errorf("error")