Files
summercms/modules/cabana/example_relation_test.go
Jakub Zych 48a5b8045a feat(12.2-03): add hasMany relation contracts, relation forms and child create
- RelationContract gains Kind (empty is belongsToMany) and ForeignKey, with kind-aware boot checks
- manage.form, view.form and pivot.form compile against the related or pivot model; $/ paths resolve inside the plugin
- view toolbarButtons accept create|update|delete|link|unlink, each the capability of its routes
- POST .../relations/{name}/records creates a child through the manage form; the server sets the hasMany key
- relation schema carries kind, deferrable and the localized forms; 17 new relation message keys in en and pl
2026-10-02 18:37:13 +02:00

27 lines
905 B
Go

package cabana_test
import "git.golem15.com/golem15/summercms/modules/cabana"
// Comment is one comment of a post: a hasMany child that points at its post
// through the nullable post_id column.
type Comment struct {
ID uint `gorm:"column:id;primaryKey"`
PostID *uint `gorm:"column:post_id"`
Author string `gorm:"column:author"`
Body string `gorm:"column:body"`
}
func (Comment) TableName() string { return "acme_blog_comments" }
// AdminRelationContracts binds the posts form's relation managers to their
// models; the framework never guesses a table or column.
func (PostsController) AdminRelationContracts() []cabana.RelationContract {
return []cabana.RelationContract{{
Name: "comments",
Kind: cabana.RelationHasMany,
NewRelated: func() any { return &Comment{} },
ForeignKey: "post_id",
Columns: map[string]string{"author": "author", "body": "body"},
}}
}