Skip to content

fix(models): declare relation return types the console requests - #142

Merged
roncodes merged 1 commit into
release/v0.4.25from
fix/relation-return-types
Oct 13, 2026
Merged

roncodes merged 1 commit into
release/v0.4.25from
fix/relation-return-types

Conversation

@roncodes

Copy link
Copy Markdown
Member

Companion to fleetbase/core-api#303, which only lets a client's with / expand / with_count name a method that declares an Eloquent Relation return type, or one listed in $withable. Before #303, any public method with no required arguments could be called through with, for example with[]=saveInstance inserted a blank row.

Under #303, these relations would stop loading because the console requests them and they have no return type. This PR adds the return types:

Model Method Type Console request
Store networks BelongsToMany store switcher (routes/application.js)
Product addonCategories, variants, files, hours HasMany product edit
ProductAddonCategory category BelongsTo product model
ProductVariant options HasMany product model
StoreLocation hours HasMany (its docblock wrongly said BelongsTo) home, settings

Merge order: merge this with #303 or before it. On today's core it changes nothing at runtime.

Fatal-error check: adding a return type is fatal for any subclass that overrides the method without one. I scanned every package for subclasses of these five models, following extends chains transitively and matching names case-insensitively, plus anonymous test subclasses. None override a typed method. No core parent or trait defines these names.

API / docs: no change in behaviour, so no fleetbase/postman or fleetbase.io update.

Other storefront with requests:

  • orders/index/view.js sends a with list that OrderController::findRecord ignores.
  • alertIncomingOrder requests fleetops Order relations (customer, payload, trackingNumber), which are already typed.
  • storefront-app's with: ['locations'] reaches NetworkController@stores, which uses fixed relations.

Validation

  • php -l on the 5 files: clean.
  • php-cs-fixer dry-run on the 5 files: clean.
  • php scripts/pest-runner.php server/tests: 689 tests, 0 failures, 23 errors. The base commit gives the same 23 errors in the same worktree. The local vendor copy lacks Fleetbase\Support\SocketCluster\* and Illuminate\Validation\Factory, so these errors are not from this change.
  • Each class loads through the autoloader, and reflection reports the declared types.

Tests: I added no new tests. The relation filtering is tested in core-api #303, and this PR only adds declarations.

core-api's RequestRelations only applies a client's with/expand/with_count
name when the method declares an Eloquent Relation return type or the model
lists it in $withable. Type the untyped relations the console asks for so
they keep loading:

- Store::networks(): BelongsToMany
- Product::addonCategories/variants/files/hours(): HasMany
- ProductAddonCategory::category(): BelongsTo
- ProductVariant::options(): HasMany
- StoreLocation::hours(): HasMany (its @return wrongly said BelongsTo)

php-cs-fixer drops the now superfluous @return docblocks and shortens the
remaining ones to the imported names.
@roncodes roncodes added needs-human-review Requires human review before proceeding type:bug Bug fix labels Oct 13, 2026
@roncodes
roncodes merged commit 181bb97 into release/v0.4.25 Oct 13, 2026
@roncodes
roncodes deleted the fix/relation-return-types branch October 13, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-human-review Requires human review before proceeding type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant