Skip to content

Commit

Permalink
chore: update README for Customize JoinTable usage
Browse files Browse the repository at this point in the history
  • Loading branch information
luantranminh committed Apr 20, 2024
1 parent 81f1a0d commit d032753
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ The provider supports the following databases:

* **Foreign key constraints not generated correctly** -
If a [Customize JoinTable](https://gorm.io/docs/many_to_many.html#Customize-JoinTable) is defined in the schema,
you need to use the provider as a [Go Program](#as-go-file) and pass to the `Load` method the tables in their dependency order. i.e.,
Join tables after their parent tables.

you need to use the provider as a [Go Program](#as-go-file) and set it up using the `WithJoinTables` option.

for example if those are your models:
```go
type Person struct {
Expand All @@ -210,7 +209,11 @@ The provider supports the following databases:

you should use the following code:
```go
stmts, err := gormschema.New("mysql").Load(&models.Person{}, &models.Address{}, &models.PersonAddress{})
stmts, err := gormschema.New("mysql")
.WithJoinTables(
gormschema.SetupJoinTableParams{Model: &models.Person{}, Field: "Addresses", JoinTable: &models.PersonAddress{}},
)
.Load(&models.Person{}, &models.Address{})
```

### License
Expand Down

0 comments on commit d032753

Please sign in to comment.