Skip to content

Commit

Permalink
fix: create table WithForeignKey() and has-many relation
Browse files Browse the repository at this point in the history
As for m2m relations, has-many relations should not emit FOREIGN KEYs.
  • Loading branch information
brueli authored Feb 25, 2022
1 parent 56c8c5e commit 3cf5649
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion query_table_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func (q *CreateTableQuery) TableSpace(tablespace string) *CreateTableQuery {

func (q *CreateTableQuery) WithForeignKeys() *CreateTableQuery {
for _, relation := range q.tableModel.Table().Relations {
if relation.Type == schema.ManyToManyRelation {
if relation.Type == schema.ManyToManyRelation ||
relation.Type == schema.HasManyRelation {
continue
}
q = q.ForeignKey("(?) REFERENCES ? (?)",
Expand Down

0 comments on commit 3cf5649

Please sign in to comment.