Skip to content

Commit

Permalink
🐛 Fix constraints on archetype tag rels (#490)
Browse files Browse the repository at this point in the history
* Adds cascading deletes to archetype tag relationships
* Surfaces the Review relationship in the archetype resource
* Removes some dead code

Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam committed Sep 21, 2023
1 parent 6b75318 commit d850515
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ func (h ArchetypeHandler) Get(ctx *gin.Context) {
return
}

archetypes := []model.Archetype{}
db = h.preLoad(h.DB(ctx), "Tags", "CriteriaTags")
result = db.Find(&archetypes)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
}

membership := assessment.NewMembershipResolver(h.DB(ctx))
applications, err := membership.Applications(m)
if err != nil {
Expand Down Expand Up @@ -325,6 +317,7 @@ type Archetype struct {
StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"`
Applications []Ref `json:"applications" yaml:"applications"`
Assessments []Ref `json:"assessments" yaml:"assessments"`
Review *Ref `json:"review"`
}

//
Expand Down Expand Up @@ -354,6 +347,11 @@ func (r *Archetype) With(m *model.Archetype) {
for _, a := range m.Assessments {
r.Assessments = append(r.Assessments, r.ref(a.ID, &a))
}
if m.Review != nil {
ref := &Ref{}
ref.With(m.Review.ID, "")
r.Review = ref
}
}

//
Expand Down
4 changes: 2 additions & 2 deletions migration/v9/model/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type Archetype struct {
Comments string
Review *Review `gorm:"constraint:OnDelete:CASCADE"`
Assessments []Assessment `gorm:"constraint:OnDelete:CASCADE"`
CriteriaTags []Tag `gorm:"many2many:ArchetypeCriteriaTags"`
Tags []Tag `gorm:"many2many:ArchetypeTags"`
CriteriaTags []Tag `gorm:"many2many:ArchetypeCriteriaTags;constraint:OnDelete:CASCADE"`
Tags []Tag `gorm:"many2many:ArchetypeTags;constraint:OnDelete:CASCADE"`
Stakeholders []Stakeholder `gorm:"many2many:ArchetypeStakeholders;constraint:OnDelete:CASCADE"`
StakeholderGroups []StakeholderGroup `gorm:"many2many:ArchetypeStakeholderGroups;constraint:OnDelete:CASCADE"`
}

0 comments on commit d850515

Please sign in to comment.