Re: [Modeling-users] Re: attaching information to a relation
Status: Abandoned
Brought to you by:
sbigaret
From: Mario R. <ma...@ru...> - 2003-08-04 19:53:58
|
On Lundi, ao=FB 4, 2003, at 20:49, Sebastien Bigaret wrote: > Mario wrote: >> just wondering how this can be best done... as a simple example, >> assume a Person and an Address tables. A Person may have >> more than one address, but each address may be categorized >> as being "primary", "secondary", "private", "work", or anything >> a priori unknown, Where does one best stick this information? > > I think this is what uml calls a "qualified association". Thanks for the explanation(s) below... This would work just fine, if an Address belongs (exclusively) to any one Person. What I am looking for is a way to reuse the same Address for different people, but the type of relation may be different each time. E.g. Mr. Dough's lives in a Villa, across from the beach (private Address) Ladi Lean is the housemaid for Mr. Dough (work Address) Mr. Dough's little sister spends summers at his villa (secondary=20 Address) ... The most natural thing to me would be to add a "property" to the association, if that'd be allowed. I guess one would have to make an addditional association table for this? mario > This is how I > would model this: > > - add a 'category' attribute to entity Address, > > - add to the Person class methods such as: > > ---------------------------------------- > def getAddresses(self, type=3DNone): > """ > Returns addresses of a given type, or all addresses if type > is None or omitted > """ > self.willRead() > if type is None: > return self._addresses > else: > return self.editingContext().fetch('Address', > 'type =3D=3D '%s'"%type) > ---------------------------------------- > > You can also do in-memory filtering w/ a qualifier, after the > > ---------------------------------------- > from Modeling.Qualifier import KeyValueQualifier > from Modeling.Qualifier import QualifierOperatorEqual > from Modeling.Qualifier import filteredArrayWithQualifier > > def getAddresses(self, type=3DNone): > """ > Returns addresses of a given type, or all addresses if type > is None or omitted > """ > self.willRead() > if type is None: > return self._addresses > else: > q=3DKeyValueQualifier('category', QualifierOperatorEqual, = type) > return filteredArrayWithQualifier(self.getAddresses(), q) > ---------------------------------------- > > (of course, when all the types are known, you can also use > inheritance) > > Cheers, > > -- S=E9bastien. |