File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
src/app/Library/CrudPanel/Traits Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -372,6 +372,12 @@ public function makeSureColumnHasNeededAttributes($column)
372372 $ column ['relation_type ' ] = $ this ->inferRelationTypeFromRelationship ($ column );
373373 }
374374
375+ // if there's a model defined, but no attribute
376+ // guess an attribute using the identifiableAttribute functionality in CrudTrait
377+ if (isset ($ column ['model ' ]) && ! isset ($ column ['attribute ' ]) && method_exists ($ column ['model ' ], 'identifiableAttribute ' )) {
378+ $ column ['attribute ' ] = (new $ column ['model ' ])->identifiableAttribute ();
379+ }
380+
375381 // check if the column exists in the database (as a db column)
376382 $ column_exists_in_db = $ this ->hasDatabaseColumn ($ this ->model ->getTable (), $ column ['name ' ]);
377383
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ class CrudPanelColumnsTest extends BaseDBCrudPanelTest
128128 'entity ' => 'accountDetails ' ,
129129 'model ' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails ' ,
130130 'relation_type ' => 'HasOne ' ,
131+ 'attribute ' => 'nickname ' ,
131132 ],
132133 'accountDetails__nickname ' => [
133134 'name ' => 'accountDetails.nickname ' ,
@@ -155,6 +156,7 @@ class CrudPanelColumnsTest extends BaseDBCrudPanelTest
155156 'relation_type ' => 'BelongsTo ' ,
156157 'entity ' => 'accountDetails.user ' ,
157158 'model ' => 'Backpack\CRUD\Tests\Unit\Models\User ' ,
159+ 'attribute ' => 'name ' ,
158160 ],
159161 ];
160162
@@ -278,6 +280,7 @@ class CrudPanelColumnsTest extends BaseDBCrudPanelTest
278280 'searchLogic ' => false ,
279281 'priority ' => 0 ,
280282 'relation_type ' => 'BelongsTo ' ,
283+ 'attribute ' => 'content ' ,
281284 ],
282285 'ac_article_content ' => [
283286 'name ' => 'accountDetails.article ' ,
You can’t perform that action at this time.
0 commit comments