statamic-rad-pack / runway

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

Model accessors shouldn't be orderable in listing table #471

Closed duncanmcclean closed 2 months ago

duncanmcclean commented 2 months ago

Description

When you have a model accessor on an Eloquent Model, with an associated field that's showing in the listing table and you go to order by that field, you get a database error about the column not existing in the database.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'order_date' in 'order clause' (Connection: mysql, SQL: select * from `orders` order by `order_date` asc limit 50 offset 0)

We should prevent fields based on model accessors from being orderable in listing tables.

Steps to reproduce

  1. Add a model accessor to a model
  2. Add a field to your resource's blueprint, with the same handle of the model accessor
  3. Add that field to your listing columns
  4. Attempt to order models by that column
  5. See database error

Environment

Environment Application Name: Statamic Laravel Version: 10.42.0 PHP Version: 8.3.0 Composer Version: 2.6.3 Environment: local Debug Mode: ENABLED URL: sc-sandbox.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

Simple Commerce Currencies: GBP Gateways: Stripe, Dummy Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EloquentCustomerRepository Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EloquentOrderRepository Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Free Shipping Tax Engine: DuncanMcClean\SimpleCommerce\Tax\BasicTaxEngine

Statamic Addons: 2 Antlers: runtime Stache Watcher: Enabled Static Caching: Disabled Version: 4.46.0 PRO

Statamic Addons duncanmcclean/simple-commerce: 6.0.1 statamic-rad-pack/runway: 6.0.4