Re: [SQLObject] Substitute fieldID for fieldName
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Andrew B. <an...@ca...> - 2006-05-08 13:07:47
|
On Mon, May 08, 2006 at 02:28:03PM +0200, Felix wrote: > Hi everyone !! > > I've a question (sorry if the email subject isn't to explicative) that i will > simplify in this example: > > Three simple tables with relations: > > class rank(SQLObject): Python code almost always has Capitalised class names (See also http://www.python.org/dev/peps/pep-0008/), i.e. "class Rank(SQLObject):". This will help make something else clearer: > id = IntCol() > title = StringCol() > persons = MultipleJoin('person') > > class kind(SQLObject): > id = IntCol() > kindName = StringCol() > persons = MultipleJoin('person') > > class person(SQLObject): > id = IntCol() > name = StringCol() > rankID = ForeignKey('rank') > kindID = ForeignKey('kind') Make these last two lines be just: rank = ForeignKey() kind = ForeignKey() (and if you name the classes "Rank" and "Kind", then there's no possible confusion to worry about here). > > What's the best way to get title and kindName instead rankID and kindID if i do person.get(1).select() (or else)? > With SQL queries i would do subslects or joins. Person.get(1).rank.title Person.get(1).kind.kindName > I think i could access through something like rank.persons or can i override _get_rankID() for getting rank title instead > rankID or add new fields in person class like: Right, you can make properties to be shortcuts to the above code snippets. -Andrew. |