Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/v2/multiple relation #778

Merged
merged 19 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ jobs:
sed -i 's/DB_PASSWORD=/DB_PASSWORD=postgres/g' .env &&
sed -i 's/DB_HOST=127.0.0.1/DB_HOST=localhost/g' .env &&
sed -i 's/DB_USERNAME=root/DB_USERNAME=postgres/g' .env &&
sed -i 's/DB_PORT=3306/DB_PORT=5432/g' .env
sed -i 's/DB_PORT=3306/DB_PORT=5432/g' .env


# Pgsql | Laravel setup
- name: Pgsql | Laravel setup
Expand Down
7 changes: 5 additions & 2 deletions src/Helpers/GetData.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ public static function getRelationData($data_type, $row)
$relational_fields = collect($data_type->dataRows)->filter(function ($value, $key) {
return $value->relation != null;
})->all();

foreach ($relational_fields as $field) {
$relation_detail = [];

Expand Down Expand Up @@ -323,7 +322,11 @@ public static function getRelationData($data_type, $row)

switch ($relation_type) {
case 'belongs_to':
$row->{$destination_table} = collect($relation_data)->first();
if (isset($row->{$destination_table})) {
array_push($row->{$destination_table}, collect($relation_data)->first());
} else {
$row->{$destination_table} = collect($relation_data)->toArray();
}
break;

case 'has_many':
Expand Down
16 changes: 13 additions & 3 deletions src/resources/js/pages/crud-generated/browse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1032,12 +1032,12 @@ export default {
handleSelect(data) {
this.selected = data;
},
displayRelationData(record, dataRow) {
displayRelationData(record, dataRow) {
if (dataRow.relation) {
const relationType = dataRow.relation.relationType;
const table = this.$caseConvert.stringSnakeToCamel(
dataRow.relation.destinationTable
);
);
this.$caseConvert.stringSnakeToCamel(
dataRow.relation.destinationTableColumn
);
Expand All @@ -1048,9 +1048,19 @@ export default {
if (relationType == "has_many") {
const list = record[table];
const flatList = list.map((ls) => {
return ls[displayColumn];
return ls[displayColumn];
});
return flatList.join(", ");
} else if(relationType == "belongs_to"){
const list = record[table];
let field = this.$caseConvert.stringSnakeToCamel(dataRow.field)
const flatList = list.map((ls) => {
if(ls.id == record[field]){
return ls[displayColumn];
}
return null
});
return flatList.join(",").replace(",", "");
} else {
return record[table] ? record[table][displayColumn] : null;
}
Expand Down
Loading