statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/addons/rad-pack/runway
MIT License
112 stars 47 forks source link

HasManyFieldtype still running sync() when read_only is set #495

Closed mefenlon closed 4 months ago

mefenlon commented 4 months ago

Description

I have a HasMany Fieldtype relationship set to read only.

          -
            handle: publication_status
            field:
              resource: publication_status
              type: has_many
              display: 'Publication Status'
              create: false
              max_items: 1
              mode: select
              always_save: false
              visibility: read_only

I would expect it to not process the field when saving.

I have found that durring the process function in src/Fieldtypes/HasManyFieldtype.php $model->{$this->field()->handle()}()->sync($data); is still being run.

Steps to reproduce

  1. Set HasMany fieldtype to read_only
  2. Edit a resource

Environment

Environment Application Name: Jazz Laravel Version: 11.7.0 PHP Version: 8.2.18 Composer Version: 2.7.4 Environment: local Debug Mode: ENABLED URL: localhost 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

Statamic Addons: 2 Sites: 1 Stache Watcher: Disabled Static Caching: Disabled Version: 5.1.0 PRO

Statamic Addons jacksleight/statamic-bard-texstyle: 3.2.2 statamic-rad-pack/runway: 7.0.0

mefenlon commented 4 months ago

Submitted a pr #496

duncanmcclean commented 4 months ago

I've left a comment on your PR: https://github.com/statamic-rad-pack/runway/pull/496#issuecomment-2120310480

You can avoid fields being saved (or processed), by adding save: false to your field config.