|
Re: Multiple source objects to single target object [message #1796687 is a reply to message #1796628] |
Wed, 17 October 2018 15:26 |
Gururaj Maddodi Messages: 7 Registered: October 2018 |
Junior Member |
|
|
In order to make it clear I added another attribute to ClassB called type of datatype Estring in the source meta-model. I tried the following method as in the code below,
main() {
Source.rootObjects()[A] -> map AToD();
}
mapping A::AToD() : D{
classe := self.classb -> map toE();
}
mapping ClassB :: toE() : ClassE
when{self.name<> "BInst2"}
{
name := self.type;
self.container().allSubobjectsOfKind(MM::ClassB) -> forEach(Var){
if(self.toString() <> Var.toString()){
if(self.type = Var.type){
classf := Var.classc -> map tof();
}endif;
}endif;
};
classf := self.classc-> map tof();
}
mapping ClassC::tof() : ClassF {
name := self.name;
}
In my source model instance I have three ClassB objects, 1: name=BInst1, type=T1, 2: name=BInst2, type=T1, and 3: name=BInst3, type=T2. Each of those have one object of ClassC, 1: name=CInst1, 2: name=CInst2, and 3: name=CInst3 respectively.
When I execute this, in the target model I have two objects of ClassE as wanted. But in target object (ClassE) with two source objects (ClassB), the target child Class (ClassF) is just one (CInst1), whereas in source model there are two (CInst1 and CInst2). The other one is on same level as ClassD.
If I change the placement of "classf := self.classc-> map tof();" before the forEach, I get CInst2 as child under ClassE and CInst2 on same level as ClassD.
Is there any way to rectify this? I tried this method as I could not find any documentation about it. I'm aware if there is any better method. Please kindly help.
|
|
|
|
Powered by
FUDForum. Page generated in 0.05273 seconds