legend-studio
legend-studio copied to clipboard
Bug: Roundtrip issue: relational class mapping `primaryKey` field is not handled properly during transformation
🐛 Bug Report
Relational class mapping primaryKey is added after transformation metamodel -> protocol
How to reproduce the issue
Use the following grammar in manual grammar roundtrip test - See https://github.com/finos/legend-studio/issues/165 for more details
Class other::Person
{
name:String[1];
firm:other::Firm[1];
address: other::Address[0..1];
}
Class other::Firm
{
legalName:String[1];
employees:other::Person[1];
address:other::Address[1];
}
Class other::Address
{
line1:String[1];
}
###Relational
Database mapping::db(
Table employeeFirmDenormTable
(
id INT PRIMARY KEY,
name VARCHAR(200),
firmId INT,
legalName VARCHAR(200),
address VARCHAR(200)
)
)
###Mapping
Mapping mappingPackage::myMapping
(
other::Person: Relational
{
name : [mapping::db]employeeFirmDenormTable.name,
firm
(
~primaryKey ([mapping::db]employeeFirmDenormTable.legalName)
legalName : [mapping::db]employeeFirmDenormTable.legalName,
address
(
line1: [mapping::db]employeeFirmDenormTable.address
)
),
address
(
line1: [mapping::db]employeeFirmDenormTable.address
)
}
)
Solution idea
We should properly create an InferableValue wrapper around this or do some logic in the transformer to omit primaryKey when it's not needed.