[Modeling-users] Re: attaching information to a relation
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-08-04 18:48:54
|
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". 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',=20 '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. |