statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.03k stars 530 forks source link

Revealer fieldtype causes saving issue with eloquent data #5977

Open jesseleite opened 2 years ago

jesseleite commented 2 years ago

Bug description

Our revealer fieldtype is throwing SQL error when in users blueprint...

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revealeo' in 'field list' (SQL: update `users` set `revealeo` = ?, `users`.`updated_at` = 2022-05-02 22:42:24 where `id` = 1)

When using our eloquent driver addon, entries save without error, but the revealer's toggle data shows up in the data column, which is also wrong.

Our revealer seems to work fine with stache data though.

How to reproduce

Try revealer fieldtype with both eloquent users and eloquent entries.

Versions

Statamic 3.3.9 Pro Laravel 9.9.0 PHP 8.1.5 statamic/eloquent-driver 0.2.0

jesseleite commented 2 years ago

Maybe https://github.com/statamic/cms/issues/6177 can help us deal with this more gracefully by making revealer fieldtypes virtual: true by default?

ryanmitchell commented 11 months ago

This issue still exists in both eloquent driver and in eloquent users. I guess it doesn't exist in YAML-land as null values are being stripped out, whereas in eloquent-land we're not doing that.

It would be simple enough in eloquent driver to remove NULL values from any entry/term/asset data - I can't think of any downsides to that, can you? a whereNull check would still be true.

For eloquent users it would just mean updating the data() method to not set when null: https://github.com/statamic/cms/blob/26d08dba17334d6bcad571e4ada3d8c66a61fbe1/src/Auth/Eloquent/User.php#L51-L53