Skip to content

Commit b97f86b

Browse files
committed
many_to_many relations coming from view
1 parent b64f8bd commit b97f86b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

model.go

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type fieldReference struct {
7373
table string
7474
condition string
7575
column string
76+
view bool // flag that related data comes from view, so no sync is required
7677
}
7778

7879
type modelField struct {
@@ -145,6 +146,9 @@ func getFieldInfo(mValue reflect.Value, fIndex int) (modelField, error) {
145146
mField.reference.table = lookForSetting(tag, "table")
146147
mField.reference.condition = lookForSettingWithSep(tag, "condition", ":")
147148
mField.Type += referenceField
149+
if lookForSetting(tag, "view") != "" {
150+
mField.reference.view = true
151+
}
148152
case lookForSetting(tag, "has_many") != "":
149153
mField.reference.Type = "has_many"
150154
mField.Type += referenceField

upsert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (ins *inserter) syncRelations(ctx context.Context, db *sql.DB, info *modelI
207207
ins.depth++
208208

209209
for _, field := range info.fields {
210-
if isManyToMany(field) {
210+
if isManyToMany(field) && !field.reference.view {
211211
if err := ins.syncManyToManyRelation(ctx, db, field, info); err != nil {
212212
return err
213213
}

0 commit comments

Comments
 (0)