feat(10-02): relation field options and relation saves with labels
- FieldRelationContract/FieldRelationProvider bind every type: relation
field to a belongsTo foreign key or a belongsToMany pivot; activation
fails naming plugin, controller and field on a missing or broken contract
- GET /{vendor}/{plugin}/{controller}/fields/{field}/options serves
{value, label} pages scoped by pact.RelationExtendOptionsQuery, behind
the controller permission; read-only and non-relation fields are 404
- Saves apply present relation keys after the Before hook: ids are
revalidated through the same scoped query (422 and full rollback
otherwise), belongsTo sets the foreign key, belongsToMany replaces pivot
rows in submitted order with the order column set to the index
- Show, create and update return relation values in data and meta.labels
- A belongsTo on a protected fill key is read-only (D-26)
- One six-segment GET pattern dispatches relation lists and field options,
which ServeMux cannot register side by side
- Admin OpenAPI documents the options route and RecordEnvelope
This commit is contained in:
@@ -495,21 +495,31 @@ func relationBaseQuery(ctx context.Context, tx *gorm.DB, cc *CompiledController,
|
||||
return q, target, nil
|
||||
}
|
||||
|
||||
func normalizeRelationQuery(schema *RelationSchema, candidates bool, in RelationQuery) (int, int, string, bool, error) {
|
||||
// normalizeRelationPage applies the Phase 9 relation paging limits: page is
|
||||
// a positive integer (default 1), per_page is 1..100 (default 20).
|
||||
func normalizeRelationPage(rawPage, rawPerPage string) (int, int, error) {
|
||||
page, per := 1, 20
|
||||
var err error
|
||||
if in.Page != "" {
|
||||
page, err = parsePositive(in.Page)
|
||||
if rawPage != "" {
|
||||
page, err = parsePositive(rawPage)
|
||||
if err != nil {
|
||||
return 0, 0, "", false, relationInvalid("page", "must be a positive integer")
|
||||
return 0, 0, relationInvalid("page", "must be a positive integer")
|
||||
}
|
||||
}
|
||||
if in.PerPage != "" {
|
||||
per, err = parsePositive(in.PerPage)
|
||||
if rawPerPage != "" {
|
||||
per, err = parsePositive(rawPerPage)
|
||||
if err != nil || per > 100 {
|
||||
return 0, 0, "", false, relationInvalid("per_page", "must be between 1 and 100")
|
||||
return 0, 0, relationInvalid("per_page", "must be between 1 and 100")
|
||||
}
|
||||
}
|
||||
return page, per, nil
|
||||
}
|
||||
|
||||
func normalizeRelationQuery(schema *RelationSchema, candidates bool, in RelationQuery) (int, int, string, bool, error) {
|
||||
page, per, err := normalizeRelationPage(in.Page, in.PerPage)
|
||||
if err != nil {
|
||||
return 0, 0, "", false, err
|
||||
}
|
||||
panel := schema.View
|
||||
if candidates {
|
||||
panel = schema.Manage
|
||||
|
||||
Reference in New Issue
Block a user