[Modeling-cvs] ProjectModeling/Modeling Relationship.py,1.13,1.14 CHANGES,1.135,1.136
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-07-26 06:21:55
|
Update of /cvsroot/modeling/ProjectModeling/Modeling
In directory sc8-pr-cvs1:/tmp/cvs-serv5376
Modified Files:
Relationship.py CHANGES
Log Message:
Added Relationship.anyInverseRelationship() --plus entity Holidays in test
model StoreEmployees, with a toMany rel. Employee-->Holidays having no
inverse. This is the first step towards the removal of the constraint on
to-many relationships that should have an inverse toOne rel. for the moment
being.
Index: Relationship.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/Relationship.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Relationship.py 24 Jul 2003 17:02:34 -0000 1.13
--- Relationship.py 25 Jul 2003 15:39:03 -0000 1.14
***************
*** 382,385 ****
--- 382,423 ----
self._joins=tuple(_joins)
+ def anyInverseRelationship(self):
+ """
+ If self.inverseRelationship() exists, return that one, otherwise build
+ and return an inverse relationship for self
+
+ See also: inverseRelationship()
+ """
+ inverse=self.inverseRelationship()
+ if inverse:
+ return inverse
+
+ # we need to make one
+ parents=self.entity().parentEntities()
+ parents.reverse() # from root to leaf (self)
+ parents.append(self.entity())
+ rel_to_inverse=None
+ for parent in parents:
+ parent_rel=parent.relationshipNamed(self.name())
+ if parent_rel:
+ rel_to_inverse=parent_rel
+ break
+
+ #inverse_name='inverse_for_%s_%s'%(self.entity().name(), self.name())
+ inverse_name='inverse_for_%s_%s'%(parent_rel.entity().name(), self.name())
+ inverse_rel=SimpleRelationship(inverse_name)
+ if self.isToOne():
+ inverse_rel.setMultiplicityUpperBound(-1)
+ else:
+ inverse_rel.setMultiplicityUpperBound(1)
+
+ inverse_rel.setEntity(self.destinationEntity())
+ for join in rel_to_inverse.joins():
+ src=self.destinationEntity().attributeNamed(join.destinationAttribute().name())
+ dst=rel_to_inverse.entity().attributeNamed(join.sourceAttribute().name())
+ inv_join=Join(src, dst)
+ inverse_rel.addJoin(inv_join)
+ return inverse_rel
+
def clone(self, entity, name=None):
"""
***************
*** 455,458 ****
--- 493,498 ----
Returns the inverse relationship in the destination entity,
or None if it does not exist
+
+ See also: anyInverseRelationship()
"""
#import pdb ; pdb.set_trace()
***************
*** 481,485 ****
# if you can't find an inverse on self.entity, we'd probably find one
# in parent entities:
! self_rels=[e.relationshipNamed(self.name()) for e in src_entities]
for self_rel in self_rels:
--- 521,534 ----
# if you can't find an inverse on self.entity, we'd probably find one
# in parent entities:
! #
! # Note: the following makes it possible to compute an inverseRelationship
! # for a relationship built by anyInverseRelationship()
! # The trick here is that such a relion is NOT added to
! # self.relationships(), so we need to explicitly add 'self'
! # instead of relying on self.entity().relationshipNamed() which in
! # this case returns None.
! self_rels=[self]
! self_rels.extend([e.relationshipNamed(self.name()) for e in src_entities
! if e != self])
for self_rel in self_rels:
***************
*** 708,712 ****
def __eq__(self, aRelationship):
"Tests whether both relationship are equal"
! if aRelationship.isFlattened():
return 0
try:
--- 757,761 ----
def __eq__(self, aRelationship):
"Tests whether both relationship are equal"
! if aRelationship is None or aRelationship.isFlattened():
return 0
try:
***************
*** 1135,1139 ****
def __eq__(self, aRelationship):
"Tests whether both relationship are equal"
! if not aRelationship.isFlattened():
return 0
try:
--- 1184,1188 ----
def __eq__(self, aRelationship):
"Tests whether both relationship are equal"
! if aRelationship is None or not aRelationship.isFlattened():
return 0
try:
Index: CHANGES
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CHANGES,v
retrieving revision 1.135
retrieving revision 1.136
diff -C2 -d -r1.135 -r1.136
*** CHANGES 24 Jul 2003 17:02:34 -0000 1.135
--- CHANGES 25 Jul 2003 15:39:03 -0000 1.136
***************
*** 8,11 ****
--- 8,17 ----
--------------------------------------------------------
+ * Added Relationship.anyInverseRelationship() --plus entity Holidays in
+ test model StoreEmployees, with a toMany rel. Employee-->Holidays having
+ no inverse. This is the first step towards the removal of the constraint
+ on to-many relationships that should have an inverse toOne rel. for the
+ moment being.
+
* Fixed bug #776996: RelationshipManipulation methods misbehaving w/
inheritance. Implied fixing: Relationship.inverseRelationship(). Also
|