[PEAK] peak.model and mappings?

Phillip J. Eby pje at telecommunity.com
Mon Feb 23 08:12:52 EST 2004


At 08:35 PM 2/22/04 -0500, Bob Ippolito wrote:
>How are you supposed to define a mapping with peak.model?  I'm looking for 
>something that would be used like this, in theory:
>
>from peak.api import *
>
>class MyElement(model.Element):
>
>     class elementToStringMapping(model.Mapping):
>         referencedKeyType = 'MyElement'
>         referencedType = model.String

There isn't such a feature type at present, I'm afraid.  But if you look at 
peak.metamodels.MOF131.Namespace, you'll see an implementation of an 
"indexed" relationship whereby a sequence of objects is also indexed in a 
mapping.  It's not quite the same thing, but for some applications it's 
actually better, since it also retains sequence information.  If your value 
objects don't reference their keys, use a tuple as the target type.  IOW, 
if your feature's singular name is 'mapping':

anElement.addMapping((key,value))

would add the key-value pair.  You can define additional verbs of course 
that do this in a cleaner-seeming way, according to your app's needs.

Or you can completely override the standard stuff and do it your own way 
altogether.




More information about the PEAK mailing list