Un-invert the logic in relationships.go
This commit is contained in:
parent
ea528d50b2
commit
8b60b97b9f
1 changed files with 8 additions and 7 deletions
|
@ -1,5 +1,9 @@
|
||||||
package bdb
|
package bdb
|
||||||
|
|
||||||
|
// ToOneRelationship describes a relationship between two tables where the local
|
||||||
|
// table has no id, and the foregin table has an id that matches a column in the
|
||||||
|
// local table, that column is also unique which changes the dynamic into a
|
||||||
|
// one-to-one style, not a to-many.
|
||||||
type ToOneRelationship struct {
|
type ToOneRelationship struct {
|
||||||
Table string
|
Table string
|
||||||
Column string
|
Column string
|
||||||
|
@ -57,11 +61,10 @@ func toOneRelationships(table Table, tables []Table) []ToOneRelationship {
|
||||||
|
|
||||||
for _, t := range tables {
|
for _, t := range tables {
|
||||||
for _, f := range t.FKeys {
|
for _, f := range t.FKeys {
|
||||||
if f.ForeignTable != table.Name || t.IsJoinTable || !f.Unique {
|
if f.ForeignTable == table.Name && !t.IsJoinTable && f.Unique {
|
||||||
continue
|
relationships = append(relationships, buildToOneRelationship(table, f, t, tables))
|
||||||
}
|
}
|
||||||
|
|
||||||
relationships = append(relationships, buildToOneRelationship(table, f, t, tables))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,11 +76,9 @@ func toManyRelationships(table Table, tables []Table) []ToManyRelationship {
|
||||||
|
|
||||||
for _, t := range tables {
|
for _, t := range tables {
|
||||||
for _, f := range t.FKeys {
|
for _, f := range t.FKeys {
|
||||||
if f.ForeignTable != table.Name || f.Unique {
|
if f.ForeignTable == table.Name && !f.Unique {
|
||||||
continue
|
relationships = append(relationships, buildToManyRelationship(table, f, t, tables))
|
||||||
}
|
}
|
||||||
|
|
||||||
relationships = append(relationships, buildToManyRelationship(table, f, t, tables))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue