def __init__(self, inst, propname, givenargs): """ Constructor. @param inst: The L{DBObject} instance. @param propname: The property name in the L{DBObject} instance that results in this class being created. @param givenargs: Any arguments given (through the use of a C{dict} in the class variable in L{DBObject} rather than a string to describe the relationship). The given args can include, for all relationships, a C{class_name}. Depending on the relationship, C{association_foreign_key} and C{foreign_key} might also be used. """ self.infl = Inflector() self.inst = inst self.dbconfig = Registry.getConfig() self.args = { 'class_name': propname, 'association_foreign_key': self.infl.foreignKey(self.infl.singularize(propname)), 'foreign_key': self.infl.foreignKey(self.inst.__class__.__name__), 'polymorphic': False } self.args.update(givenargs) otherklassname = self.infl.classify(self.args['class_name']) if not self.args['polymorphic']: self.otherklass = Registry.getClass(otherklassname) self.othername = self.args['association_foreign_key'] self.thisclass = self.inst.__class__ self.thisname = self.args['foreign_key']
def get_polymorphic(row): kid = getattr(row, "%s_id" % self.args['class_name']) kname = getattr(row, "%s_type" % self.args['class_name']) return Registry.getClass(kname).find(kid)