# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
Relationship manipulation API
The framework supplies a default implementation for this API.
CVS information
$Id: RelationshipManipulation.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
try:
from Interface import Base
except:
class Base:
pass
from Modeling.interfaces.KeyValueCoding import KeyValueCodingInterface
class RelationshipManipulationInterface(KeyValueCodingInterface):
"""
The RelationshipManipulation interface defines all methods needed to
manipulates relationships defined in a Model (see Model, Entity,
Relationship and ClassDescription).
Its behaviour is similar to KeyValueCoding except that it does only handle
keys mapped to relationships in the receivers' class descriptions.
Implemented by: mix-in class RelationshipManipulation
"""
def addObjectToBothSidesOfRelationshipWithKey(self, anObject, aKey):
"""
Adds object to the corresponding relationship, and adds 'self'
to 'anObject' 's inverse relationship, if it exists.
Raises TypeError if 'aKey' cannot be found among the relationships of the
receivers' class description.
"""
def addObjectToPropertyWithKey(self, anObject, aKey):
"""
Depending on the relationship, the method performs the foowing steps:
toOne relationship -- simply sets the property using
KeyValueCoding.takeValueForKey
toMany relationships -- tries to add 'anObject' with method
'addTo<Key>', or directly access the underlying set using
KeyValueCoding.valueForKey(), adds 'anObject' to that set and sets it
back in 'anObject' with 'KeyValueCoding.takeValueForKey()'.
"""
def removeObjectFromBothSidesOfRelationshipWithKey(self, anObject, aKey):
"""
Simply returns if anObject is None ('n issues a log at warning level)
"""
def removeObjectFromPropertyWithKey(self, anObject, aKey):
"""
Depending on the relationship, the method performs the following steps:
toOne relationship -- simply removes the property using
'KeyValueCoding.takeValueForKey(null)'
toMany relationships -- tries to remove 'anObject' with method
'addTo<Key>', or directly access the underlying set using
'KeyValueCoding.valueForKey()', removes 'anObject' to that set and
sets it back in 'anObject' with 'KeyValueCoding.takeValueForKey()'.
Method raise 'ValueError' if relationship 'aKey' cannot be found, or
if 'anObject' is not set for that key.
"""
def classDescription(self):
"""
Returns the class description for the receiver.
This is the only method for which RelationshipManipulation does not define
any default implementation ; it is usually implemented by objects
implementing the DatabaseObject interface, such as CustomObject
subclasses
"""
|