GetMetaEntityValuesMap retrieves a map of meta UUIDs to their linked entity values for a given list of meta UUIDs
(ctx context.Context, metaUuids []string)
| 347 | |
| 348 | // GetMetaEntityValuesMap retrieves a map of meta UUIDs to their linked entity values for a given list of meta UUIDs |
| 349 | func (s *evSqlImpl) GetMetaEntityValuesMap(ctx context.Context, metaUuids []string) (map[string][]*idm.EntityValue, error) { |
| 350 | if len(metaUuids) == 0 { |
| 351 | return nil, nil |
| 352 | } |
| 353 | |
| 354 | var relations []struct { |
| 355 | MetaUUID string |
| 356 | EVUuid string |
| 357 | EVLabel string |
| 358 | EVEntityUUID string |
| 359 | } |
| 360 | |
| 361 | db := s.Session(ctx) |
| 362 | relTable := sql.TableNameFromModel(db, &MetaValuesRel{}) |
| 363 | evTable := sql.TableNameFromModel(db, &EntityValues{}) |
| 364 | |
| 365 | relTable = sql.QuoteTo(db, relTable) |
| 366 | evTable = sql.QuoteTo(db, evTable) |
| 367 | |
| 368 | tx := db.Model(&EntityValues{}). |
| 369 | Select( |
| 370 | fmt.Sprintf("%s.meta_uuid, %s.uuid as ev_uuid, %s.label as ev_label, %s.entity_uuid as ev_entity_uuid", |
| 371 | relTable, evTable, evTable, evTable)). |
| 372 | Joins(fmt.Sprintf("INNER JOIN %s ON %s.uuid = %s.e_value_uuid", relTable, evTable, relTable)). |
| 373 | Where(fmt.Sprintf("%s.meta_uuid IN ?", relTable), metaUuids). |
| 374 | Scan(&relations) |
| 375 | |
| 376 | if tx.Error != nil { |
| 377 | return nil, evTagError(tx.Error) |
| 378 | } |
| 379 | |
| 380 | result := make(map[string][]*idm.EntityValue) |
| 381 | for _, rel := range relations { |
| 382 | ev := &idm.EntityValue{ |
| 383 | Uuid: rel.EVUuid, |
| 384 | Label: rel.EVLabel, |
| 385 | EntityUuid: rel.EVEntityUUID, |
| 386 | } |
| 387 | result[rel.MetaUUID] = append(result[rel.MetaUUID], ev) |
| 388 | } |
| 389 | |
| 390 | return result, nil |
| 391 | } |
no test coverage detected