finos/legend-studio

Bug: Fix issue with casting of subType when property mapping points to class mapping of subType

gayathrir11 opened this issue · 0 comments

Similar issues

  • I have searched and found no existing similar issues

How are you using Studio?

Legend Studio

Current and expected behavior

Whenever a property of type Class is mapped to it's subType and we DND that property we cast to type of Class it belongs to, instead of doing this we should cast the property to the subClass it is actually mapped to.

Steps to reproduce

Copy paste below grammar. Try to DnD Zipcode when you query Firm

Model data

###Relational
Database model::Test
(
  Table FirmTable
  (
    id INTEGER PRIMARY KEY,
    Legal_name VARCHAR(200)
  )
  Table PersonTable
  (
    id INTEGER PRIMARY KEY,
    firm_id INTEGER,
    firstName VARCHAR(200),
    lastName VARCHAR(200)
  )
  Table AddressTable
  (
    id INTEGER PRIMARY KEY,
    firm_id INTEGER,
    name VARCHAR(200)
  )

  Join FirmPerson(PersonTable.firm_id = FirmTable.id)
  Join FirmAddress(PersonTable.firm_id = FirmTable.id)
)


###Pure
Class model::Street extends model::Address
{
  zipcode: Integer[1];
}

Class model::Person
{
  firstName: String[1];
  lastName: String[1];
  address: model::Address[1];
}

Class model::Firm extends model::LegalEntity
[
  validName: $this.legalName->startsWith('_')
]
{
  employees: model::Person[1..*];
}

Class model::LegalEntity
{
  legalName: String[1];
  Name: String[1];
}

Class model::Address
{
  streetName: String[1];
}

Class model::Colony extends model::Street
{
  id: String[1];
}


###Mapping
Mapping model::NewMapping
(
  *model::Firm: Relational
  {
    ~primaryKey
    (
      [model::Test]FirmTable.id
    )
    ~mainTable [model::Test]FirmTable
    employees[model_Person]: [model::Test]@FirmPerson,
    Name: [model::Test]@FirmPerson
  }
  *model::Person: Relational
  {
    ~primaryKey
    (
      [model::Test]PersonTable.id
    )
    ~mainTable [model::Test]PersonTable
    firstName: [model::Test]PersonTable.firstName,
    lastName: [model::Test]PersonTable.lastName,
    address() Inline[colony]
  }
  *model::LegalEntity: Operation
  {
    meta::pure::router::operations::inheritance_OperationSetImplementation_1__SetImplementation_MANY_()
  }
  *model::Colony[colony]: Relational
  {
    ~primaryKey
    (
      [model::Test]AddressTable.id
    )
    ~mainTable [model::Test]AddressTable
    zipcode: [model::Test]AddressTable.id,
    streetName: [model::Test]AddressTable.name,
    id: [model::Test]AddressTable.id
  }
)


###Connection
RelationalDatabaseConnection model::MyC
{
  store: model::Test;
  type: H2;
  specification: LocalH2
  {
    testDataSetupSqls: [
      'Drop table if exists FirmTable;\r\nDrop table if exists PersonTable;\r\nCreate Table FirmTable(id INT, Legal_Name VARCHAR(200));\r\nCreate Table PersonTable(id INT, firm_id INT, lastName VARCHAR(200), firstName VARCHAR(200));\r\nInsert into FirmTable (id, Legal_Name) values (1, \'FirmX\');\r\nInsert into PersonTable (id, firm_id, lastName, firstName) values (1, 1, \'John\', \'Doe\');\r\n'
      ];
  };
  auth: DefaultH2;
}


###Runtime
Runtime model::Runtime
{
  mappings:
  [
    model::NewMapping
  ];
  connections:
  [
    model::Test:
    [
      connection_1: model::MyC
    ]
  ];
}

Environment

No response

Possible solution and workaround

No response

Contribution

  • I would like to work on the fix for this issue