From ccb7556281eb810ba55273fa37cf04612645ff7f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 26 Jul 2017 17:06:58 -0700 Subject: [PATCH] Fixes javascript error when custom fields exist but do not belong to any fieldsets or models --- app/Presenters/AssetPresenter.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index ff47daa28..3f60a613e 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -184,7 +184,17 @@ class AssetPresenter extends Presenter ], ]; - $fields = CustomField::all(); + // This looks complicated, but we have to confirm that the custom fields exist in custom fieldsets + // *and* those fieldsets are associated with models, otherwise we'll trigger + // javascript errors on the bootstrap tables side of things, since we're asking for properties + // on fields that will never be passed through the REST API since they're not associated with + // models. We only pass the fieldsets that pertain to each asset (via their model) so that we + // don't junk up the REST API with tons of custom fields that don't apply + + $fields = CustomField::whereHas('fieldset', function ($query) { + $query->whereHas('models'); + })->get(); + foreach ($fields as $field) { $layout[] = [ "field" => 'custom_fields.'.$field->convertUnicodeDbSlug(),