MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - Constraint on objects' properties for relationship
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Constraint on objects' properties for relationship

 Post Reply Post Reply
Author
Message
zjf View Drop Down
Member
Member


Joined: 10.Jul.2016
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote zjf Quote  Post ReplyReply Direct Link To This Post Topic: Constraint on objects' properties for relationship
    Posted: 25.Jul.2016 at 18:42
I want to put a constraint on relationships so they check their objects' properties. I have two object types, Task and Team, and both have a property, Capability, which is a collection of objects. A Team can only have a relationship to a Task if the Team's Capability property contains all the items mentioned in the Task's Capability property. Otherwise the relationship is wrong and an error message should be displayed.

In OCL this constraint could be written like this:
(if (self.ownedperform->isEmpty()=false) then
   (self.ownedperform.OwnedTeam.Members.CapabilitesOfTask->includesAll(self.ownedCapability))
else 
   true
endif)


Edited by stevek - 26.Jul.2016 at 11:06
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 25.Jul.2016 at 19:47
You can make a symbol for the relationship that uses a generator to display the missing Capabilities. There are several ways you could do this; I'll show two. Here's a way that only uses simple MERL commands. Note that the ;1 level number in .Team;1 and id;1 means "do this on the element one loop further out".
do .Task:Capability 
{  $found = ''
   do .Team;1:Capability { if id = id;1 then $found = 'T' endif }
   if not $found='T' then id ' ' endif
}

In the second way, to make it a little faster, you can avoid having to navigate N*M times to Team Capabilities. Instead, save them one per line in a variable $caps, then looking up each Task Capability in $caps using a =~ wildcard comparison.
$caps = __(newline do .Team:Capability { id newline })
do .Task:Capability 
{  if not $caps =~ __('*' newline id newline '*') then id ' ' endif
}
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.027 seconds.