def set(self, state, dict_, initiator, passive=attributes.PASSIVE_OFF, check_old=None, pop=False): # Set us on the state. dict_[self.key] = initiator if initiator is None: # Nullify relationship args dict_[self.parent_token.id.key] = None dict_[self.parent_token.discriminator.key] = None else: # Get the primary key of the initiator and ensure we # can support this assignment. mapper = class_mapper(type(initiator)) if len(mapper.primary_key) > 1: raise sa_exc.InvalidRequestError( 'Generic relationships against tables with composite ' 'primary keys are not supported.') pk = mapper.identity_key_from_instance(initiator)[1][0] # Set the identifier and the discriminator. discriminator = table_name(initiator) dict_[self.parent_token.id.key] = pk dict_[self.parent_token.discriminator.key] = discriminator
def set(self, state, dict_, initiator, passive=attributes.PASSIVE_OFF, check_old=None, pop=False): # Set us on the state. dict_[self.key] = initiator # Get the primary key of the initiator and ensure we # can support this assignment. mapper = class_mapper(type(initiator)) if len(mapper.primary_key) > 1: raise sa_exc.InvalidRequestError( 'Generic relationships against tables with composite ' 'primary keys are not supported.') pk = mapper.identity_key_from_instance(initiator)[1][0] # Set the identifier and the discriminator. discriminator = table_name(initiator) dict_[self.parent_token.id.key] = pk dict_[self.parent_token.discriminator.key] = discriminator
def class_from_table_name(state, table): for class_ in state.class_._decl_class_registry.values(): name = table_name(class_) if name and name == table: return class_ return None
def is_type(self, other): discriminator = table_name(other) return self.property._discriminator_col == discriminator
def __eq__(self, other): discriminator = table_name(other) q = self.property._discriminator_col == discriminator q &= self.property._id_col == other.id return q