Skip to content

Commit c69709b

Browse files
committed
make it non breakable for 4.1
1 parent 2ae7ed1 commit c69709b

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

src/app/Library/CrudPanel/CrudColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CrudColumn
3232

3333
public function __construct($name)
3434
{
35-
$column = $this->crud()->firstColumnWhere('key', str_replace('.', '__', $name));
35+
$column = $this->crud()->firstColumnWhere('name', $name);
3636

3737
// if column exists
3838
if ((bool) $column) {

src/app/Library/CrudPanel/CrudPanel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function getRelatedEntriesAttributes($model, $relationString, $attribute)
385385
//if attribute does not exist in main array we have more than one entry OR the attribute
386386
//is an acessor that is not in $appends property of model.
387387
if (! isset($entries[$attribute])) {
388-
//we first check if we don't have the attribute because it's and acessor that is not in appends.
388+
//we first check if we don't have the attribute because it's an acessor that is not in appends.
389389
if ($model_instance->hasGetMutator($attribute) && isset($entries[$modelKey])) {
390390
$entry_in_database = $model_instance->find($entries[$modelKey]);
391391
$attributes[$entry_in_database->{$modelKey}] = $this->parseTranslatableAttributes($model_instance, $attribute, $entry_in_database->{$attribute});
@@ -458,7 +458,7 @@ public function parseTranslatableAttributes($model, $attribute, $value)
458458
*/
459459
private function getRelatedEntries($model, $relationString)
460460
{
461-
$relationArray = explode('.', $relationString);
461+
$relationArray = explode('.', $this->getOnlyRelationEntity(['entity' => $relationString]));
462462
$firstRelationName = Arr::first($relationArray);
463463
$relation = $model->{$firstRelationName};
464464

src/app/Library/CrudPanel/Traits/ColumnsProtectedMethods.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ protected function makeSureColumnHasEntity($column)
150150

151151
// if it has parameters it's not a relation method.
152152
$column['entity'] = $this->modelMethodHasParameters($this->model, $possibleMethodName) ? false : $column['name'];
153-
if (method_exists($model, $possibleMethodName)) {
154-
$parts = explode('.', $column['name']);
155-
$relation = $column['name'];
153+
154+
$parts = explode('.', $column['entity']);
155+
156156
$attribute_in_relation = false;
157157

158158
// here we are going to iterate through all relation parts to check
@@ -161,15 +161,9 @@ protected function makeSureColumnHasEntity($column)
161161
try {
162162
$model = $model->$part()->getRelated();
163163
} catch (\Exception $e) {
164-
$relation = join('.', array_slice($parts, 0, $i));
165164
$attribute_in_relation = true;
166165
}
167166
}
168-
169-
if (! isset($column['type'])) {
170-
$column['name'] = $column['entity'] = $relation;
171-
}
172-
173167
// if the user setup the attribute in relation string, we are not going to infer that attribute from model
174168
// instead we get the defined attribute by the user.
175169
if ($attribute_in_relation) {

tests/Unit/CrudPanel/CrudPanelColumnsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class CrudPanelColumnsTest extends BaseDBCrudPanelTest
130130
'relation_type' => 'HasOne',
131131
],
132132
'accountDetails__nickname' => [
133-
'name' => 'accountDetails',
133+
'name' => 'accountDetails.nickname',
134134
'label' => 'AccountDetails.nickname',
135135
'type' => 'relationship',
136136
'key' => 'accountDetails__nickname',
@@ -140,7 +140,7 @@ class CrudPanelColumnsTest extends BaseDBCrudPanelTest
140140
'orderable' => false,
141141
'searchLogic' => false,
142142
'relation_type' => 'HasOne',
143-
'entity' => 'accountDetails',
143+
'entity' => 'accountDetails.nickname',
144144
'model' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails',
145145
],
146146
'accountDetails__user' => [

0 commit comments

Comments
 (0)