Skip to content

Commit 20bc1e8

Browse files
bidirectional option works now for relationships created by column reference
1 parent ba4b66a commit 20bc1e8

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

example/app/schema.pqt.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/generator/tables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func schema(sn string) *pqt.Schema {
2121
"news_title",
2222
pqt.TypeText(),
2323
pqt.WithNotNull(),
24-
pqt.WithReference(title, pqt.WithBidirectional(), pqt.WithInversedName("news_by_title")),
24+
pqt.WithReference(title, pqt.WithBidirectional(), pqt.WithOwnerName("comments_by_news_title"), pqt.WithInversedName("news_by_title")),
2525
))
2626

2727
category := pqt.NewTable("category", pqt.WithTableIfNotExists()).

table.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ func (t *Table) FullName() string {
5353
// AddColumn adds column to the table.
5454
func (t *Table) AddColumn(c *Column) *Table {
5555
if c.Reference != nil {
56-
t.OwnedRelationships = append(t.OwnedRelationships, newRelationship(t, c.Reference.Table, nil, RelationshipTypeManyToOne, c.ReferenceOptions...))
56+
r := newRelationship(t, c.Reference.Table, nil, RelationshipTypeManyToOne, c.ReferenceOptions...)
57+
t.OwnedRelationships = append(t.OwnedRelationships, r)
58+
if r.Bidirectional && r.InversedTable != nil {
59+
r.InversedTable.InversedRelationships = append(r.InversedTable.InversedRelationships, r)
60+
}
61+
5762
t.AddConstraint(&Constraint{
5863
Type: ConstraintTypeForeignKey,
5964
Table: t,

0 commit comments

Comments
 (0)