u could workaround by adding another python property to Pet: class Pet: directspecies = property( lambda self: self.species.species, ...)
svil On Sunday 15 April 2007 02:51:07 Brendan Arnold wrote: > Hi there, > > Lets say I have a table with a foreign key that relates to another > table with and 'id' field and a string field i.e. > > pets_table = Table('pets', meta, > Column('id', Integer), > Column('name', String), > Column('species_id', Integer, ForeignKey='species.id') > ) > > species_table = Table('species', meta, > Column('id', Integer), > Column('species', String) > ) > > class Pet(object): > def __repr__(self): > return "%s" % (self.__class__.__name__) > > class Species(object): > def __repr__(object): > return "%s" % (self.__class__.__name__) > > mapper(Pet, pets_table, properties = { > 'species' : relation(Species) > } > > Say pet is an instance of Pet. The species string gets mapped as > pet.species.species when really It'd be best for pet.species to > return the string and not bother with the redundant Species object. > I could redefine __repr__ to return self.species but the Species > object is still attached and without any debugging string. > > Is there a way to map data found in a table column directly to the > principal ORM object without having to use a 'redundant' extra ORM > object? > > Regards, > > Brendan > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [EMAIL PROTECTED] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---