Skip to content

Commit

Permalink
Fix property sequence on routing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrudula-gs committed Oct 31, 2024
1 parent 654a08c commit 3d96464
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ function meta::pure::mapping::allEnumerationMappings(m: Mapping[1]): Enumeration
$m.enumerationMappings->concatenate($m.includes->map(i | $i.included->allEnumerationMappings()))
}

function meta::pure::mapping::getEnumAndSourceValues(e:meta::pure::mapping::EnumerationMapping<Any>[1]):Pair<String,List<String>>[*]
{
$e.enumValueMappings->map(e|pair($e.enum->id(), list($e.sourceValues->map(s|$s->toString()))));
}

function meta::pure::mapping::allSuperSetImplementations(set :PropertyMappingsImplementation[1], m:Mapping[1]):PropertyMappingsImplementation[*]
{
if ($set.superSetImplementationId->isEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ function meta::pure::router::routing::resolveVar(va:VariableExpression[1], state
let res = $state.propertyMap.v->filter(p|$p.first == $va.name);
let fullRes = if (!$res->isEmpty(),
|let routed = $res.second->evaluateAndDeactivate()->cast(@ExtendedRoutedValueSpecification)->at(0)->toOne();
^$state(value=^$routed(value = $va));,
^$state(value=^$routed(value = $va, genericType = $va.genericType));,
|^$state(value=$va)
);
print(if($debug.debug,|$debug.space+'~>V) ('+$fullRes.routingStrategy.toString()+') '+$fullRes.value->evaluateAndDeactivate()->cast(@ValueSpecification)->toOne()->asString()+'\n',|''));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3500,8 +3500,11 @@ function <<access.private>> meta::relational::functions::pureToSqlQuery::process

let distinctTransformers = $propertyMappings->filter(m|$m->instanceOf(RelationalPropertyMapping))->cast(@RelationalPropertyMapping).transformer->distinct();
let semiStructuredMappings = $propertyMappings->filter(m|$m->instanceOf(RelationalPropertyMapping))->forAll(x|$x->instanceOf(SemiStructuredRelationalPropertyMapping));
if ($distinctTransformers->size() > 1,
| assertFalse($distinctTransformers->cast(@EnumerationMapping<Any>)->map(e | $e->meta::pure::mapping::getEnumAndSourceValues()->list())->distinct()->size() > 1, 'Unable to determine a unique Enum property mapping for an if stmt (returning an Enum)');,
| [];
);

assertFalse($distinctTransformers->size() > 1, 'Unable to determine a unique Enum property mapping for an if stmt (returning an Enum)');
if ($semiStructuredMappings,
| print(if(!$context.debug, |'', |$context.space+' Ignoring distinct transformer check as all property mappings are semi structured property mappings\n'));,
| assertFalse($distinctTransformers->isEmpty(), 'Unable to determine the Enum property mapping for an if stmt (returning an Enum)');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,26 @@ function <<test.Test>> meta::relational::tests::projection::enumeration::testTds
let tds = $result.values->at(0);
assertSize($tds.rows, 3);
}

function <<test.Test>> meta::relational::tests::projection::enumeration::testEnumValueReturnedInIfExpMatch():Boolean[1]
{
let result = execute({|Employee.all()->project(
[
x|$x.type,
x|if(true,
| $x.type,
| $x.type
)
],
[
'Type' ,
'Type If'
]
);
}, employeeTestMapping, enumTestRuntime(), meta::relational::extension::relationalExtensions()
);

assertSameElements($result.values.rows.getEnum('Type If'), $result.values.rows.getEnum('Type'));
let tds = $result.values->at(0);
assertSize($tds.rows, 3);
}

0 comments on commit 3d96464

Please sign in to comment.