Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Multiple source objects to single target object
Multiple source objects to single target object [message #1796628] Tue, 16 October 2018 15:21 Go to next message
Gururaj Maddodi is currently offline Gururaj MaddodiFriend
Messages: 7
Registered: October 2018
Junior Member
Hello,

I'm new to QVT. The problem I have is to map several source objects to one target object based on some criteria such as same attribute value. An example is as below,

Source and target meta-models are attached. Now when transforming, all objects of ClassB with same value for attribute name should be in one ClassE object. So, basically number of source objects for ClassB is greater than that of ClassE after transformation. However, the number of objects of ClassC should be same as that of ClassF after transformation.

I'm not sure how to achieve this. Any suggestion will be very helpful.
Re: Multiple source objects to single target object [message #1796687 is a reply to message #1796628] Wed, 17 October 2018 15:26 Go to previous messageGo to next message
Gururaj Maddodi is currently offline Gururaj MaddodiFriend
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.
Re: Multiple source objects to single target object [message #1834621 is a reply to message #1796687] Fri, 13 November 2020 16:17 Go to previous message
pere joseph rodríguez is currently offline pere joseph rodríguezFriend
Messages: 51
Registered: October 2014
Member
Maybe ia because it should be classf+=self.classc->map tof()
when you use the -> pointer is because it refers to a collection, and you expect to get a collection as result, because it invokes the map foreac element in the collection.
But if you use the assignment operator := on a collection, imstead of adding elements, you set the assigned element as the only element in the target collection.
Previous Topic:Create references between models
Next Topic:QVTo transformation from command line
Goto Forum:
  


Current Time: Thu Apr 25 10:10:55 GMT 2024

Powered by FUDForum. Page generated in 0.02891 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top