fix: [Component:CRUD] Allow edit of meta-fields and added group_by clause

pull/37/head
mokaddem 2020-12-08 10:31:17 +01:00
parent ff1f8bfc97
commit 52fef41f3c
2 changed files with 3 additions and 2 deletions

View File

@ -247,6 +247,7 @@ class CRUDComponent extends Component
$query->innerJoinWith('MetaTemplateFields', function ($q) {
return $q->contain('MetaFields')->innerJoinWith('MetaFields');
});
$query->group(['MetaTemplates.id']);
$metaTemplates = $query->all();
$data['metaTemplates'] = $metaTemplates;
return $data;
@ -262,7 +263,7 @@ class CRUDComponent extends Component
$metaFields = $query->all();
$data['metaFields'] = [];
foreach($metaFields as $metaField) {
$data['metaFields'][$metaField->field] = $metaField->value;
$data['metaFields'][$metaField->meta_template_id][$metaField->field] = $metaField->value;
}
return $data;
}

View File

@ -9,7 +9,7 @@ foreach($metaTemplatesData as $i => $metaTemplate) {
$fieldsHtml = '';
foreach ($metaTemplate->meta_template_fields as $metaField) {
$metaField->label = Inflector::humanize($metaField->field);
$metaField->field = sprintf('%s.%s.%s', 'metaFields', $metaTemplate->id, $metaField->field);
$metaField->field = sprintf('%s.%s.%s', 'metaFields', $metaField->meta_template_id, $metaField->field);
$fieldsHtml .= $this->element(
'genericElements/Form/fieldScaffold', [
'fieldData' => $metaField->toArray(),