Hey Jonathan, Welcome to ORMs :P
I think your basic misunderstanding here is that with an ORM you're going to be mapping columns -- potentially brought together from different tables -- into a single cohesive unit that represents a logical grouping, rather then collapsing everything into a bucket. Drawing from the examples in the docs, you might have a "Users" class in Python that is -- and this is the cool part -- automatically populated, committed, updated, deleted, etc. by the ORM engine, in this case SQLAlchemy. So basically you don't deal with pre-caching your records anymore, for a couple good reasons, two of which being pre-caching can be hideously expensive depending on the size of the recordset, and second, it's often simpler to request specific results when needed. Looking at your example code, I'd suspect something like the following may be what you're looking for: class Instance(object): pass class InstanceType(object): pass Instance.mapper = mapper(Instance, instance) InstanceType.mapper = mapper(InstanceType, instance_type) # This could easily be rolled into the above Instance.mapper declaration, but # for transparency we'll keep it separate. Instance.mapper.add_property('type', relation(InstanceType.mapper) # Now that we have the class objects set up, we can access them like: myins = Instance.mapper.get(5) # Get the Instance with a primary key of 5 print 'Instance number 5 is of type:', myins.type.name # You could also search by instance name. This produces the first Instance # that matches the name 'FOO'. myins = Instance.mapper.select_by(instance.c.name = 'FOO')[0] There's lots of other ways to do these things, and the documentation is fairly extensive. There's also a introduction/tutorial, state unknown at: http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/doc/build/content/tutorial.txt And, as always, irc://irc.freenode.net/#myghty where a few of us hang out :) Cheers!, -G On Tuesday, April 25, 2006, 6:42:26 PM, you wrote: > I'm new to ORMs, so please forgive me for this: > I've got a few tables where there's an integer column that foreign > keys another table for a text value. > I'm used to just pre-caching all of the values and doing a lookup like > instance_type_id = _dbcache['instance_type']['name'] > [ instance_type_name ] > or > instance_type_name = _dbcache['instance_type']['id'] > [ instance_type_id ] > I'm thinking that considering all the things the mapper does, somehow > takes care of this as well. > Can someone point me in the right direction. > instance = Table('instance', __engine__, > Column('id', Integer, primary_key=True), > Column('instance_type_id' , Integer , ForeignKey > ("instance_type.id") ), > Column('name', String(255)), > ) > instance_type = Table('instance_type', __engine__, > Column('id', Integer, primary_key=True), > Column('name', String(255), unique=True), > ) > Thanks. > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users