statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/runway
MIT License
107 stars 43 forks source link

Related resource property does not recognize underscore in handle name #476

Closed Boefjim closed 2 months ago

Boefjim commented 2 months ago

Description

When creating a blueprint with a has_many field, it does not function correctly when the resource property of the field has a value that references to a handle containing underscores. Instead it only works when the handle is entered with the underscores stripped. So the user_review.yaml resources has to be referenced by entering userreview which makes it harder to read, especially for resources with multiple parts (for example user_review_response would become userreviewresponse)

Steps to reproduce

  1. Create an user_review.yaml blueprint
  2. Create an user.yaml blueprint with this field:
    - handle: reviews
    field:
      display: 'Reviews'
      type: has_many
      resource: user_review
  3. See the error message:
    Runway could not find [user_review]. Please ensure its configured properly and you're using the correct handle. (View: /var/www/html/vendor/doublethreedigital/runway/resources/views/index.blade.php)

Environment

Environment Application Name: intranet Laravel Version: 9.52.16 PHP Version: 8.2.10-2ubuntu1 Composer Version: 2.5.8 Environment: local Debug Mode: ENABLED URL: intranet.test Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file

Sentry Enabled: MISSING DSN Environment: local Laravel SDK Version: 4.2.0 PHP SDK Version: 4.6.0 Release: NOT SET Sample Rate Errors: 100% Sample Rate Performance Monitoring: 0% Sample Rate Profiling: NOT SET Send Default PII: DISABLED

Statamic Addons: 2 Antlers: regex Sites: 1 Stache Watcher: Enabled Static Caching: Disabled Version: 4.48.0 PRO

Statamic Addons doublethreedigital/runway: 5.6.1 statamic/eloquent-driver: 2.10.0

Statamic Eloquent Driver Asset Containers: file Assets: eloquent Blueprints: file Collection Trees: file Collections: file Entries: eloquent Forms: eloquent Global Sets: eloquent Global Variables: file Navigation Trees: file Navigations: eloquent Revisions: eloquent Taxonomies: file Terms: eloquent

duncanmcclean commented 2 months ago

Runway will generate a "handle" for each of your resources, you can see these handles by running php please runway:resources:

CleanShot 2024-05-03 at 11 25 04

I've opened a PR to fix this (#480) but since it'd be a breaking change for existing sites, it'll be released as part of v7 which'll be released alongside Statamic 5.

duncanmcclean commented 2 months ago

In the meantime, you can override the handle of the resource in your Runway config:

UserReview::class => [
    'handle' => 'user_review',
],