gotosocial/vendor/github.com/uptrace/bun/schema/relation.go
dependabot[bot] 362afe8da3
[chore]: Bump github.com/uptrace/bun/extra/bunotel from 1.2.1 to 1.2.5
Bumps [github.com/uptrace/bun/extra/bunotel](https://github.com/uptrace/bun) from 1.2.1 to 1.2.5.
- [Release notes](https://github.com/uptrace/bun/releases)
- [Changelog](https://github.com/uptrace/bun/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uptrace/bun/compare/v1.2.1...v1.2.5)

---
updated-dependencies:
- dependency-name: github.com/uptrace/bun/extra/bunotel
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-04 06:45:50 +00:00

45 lines
1,015 B
Go

package schema
import (
"fmt"
)
const (
InvalidRelation = iota
HasOneRelation
BelongsToRelation
HasManyRelation
ManyToManyRelation
)
type Relation struct {
// Base and Join can be explained with this query:
//
// SELECT * FROM base_table JOIN join_table
Type int
Field *Field
JoinTable *Table
BasePKs []*Field
JoinPKs []*Field
OnUpdate string
OnDelete string
Condition []string
PolymorphicField *Field
PolymorphicValue string
M2MTable *Table
M2MBasePKs []*Field
M2MJoinPKs []*Field
}
// References returns true if the table to which the Relation belongs needs to declare a foreign key constraint to create the relation.
// For other relations, the constraint is created in either the referencing table (1:N, 'has-many' relations) or a mapping table (N:N, 'm2m' relations).
func (r *Relation) References() bool {
return r.Type == HasOneRelation || r.Type == BelongsToRelation
}
func (r *Relation) String() string {
return fmt.Sprintf("relation=%s", r.Field.GoName)
}