Re: [SQLObject] Creating table using "createTable" fails partly?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2005-07-27 16:28:50
|
On Mon, Jul 25, 2005 at 05:08:55PM +0200, Berthold H?llmann wrote: > import sqlobject > > conn = 'sqlite:///tmp/database.db' > > class _GLSQLObject(sqlobject.SQLObject): > _connection = conn > class sqlmeta: > # style = MixedCaseStyle(longID=True) > style = sqlobject.MixedCaseUnderscoreStyle(longID=True) > > class Project(_GLSQLObject): > workpackages = sqlobject.RelatedJoin('Workpackage') > name = sqlobject.StringCol() > leader = sqlobject.ForeignKey('Person') > steeringCommittee = sqlobject.RelatedJoin('Person') > > class Workpackage(_GLSQLObject): > name = sqlobject.StringCol() > > class Person(_GLSQLObject): > firstName = sqlobject.StringCol() > > def create(): > Project.createTable() > Workpackage.createTable() > Person.createTable() > > if __name__ == '__main__': > create() The correct version of the program is: #! /usr/bin/env python import sqlobject conn = 'sqlite:/:memory:?debug=1' class _GLSQLObject(sqlobject.SQLObject): _connection = conn class sqlmeta: # style = MixedCaseStyle(longID=True) style = sqlobject.MixedCaseUnderscoreStyle(longID=True) class Project(_GLSQLObject): workpackages = sqlobject.RelatedJoin('Workpackage') name = sqlobject.StringCol() leader = sqlobject.ForeignKey('Person') steeringCommittee = sqlobject.RelatedJoin('Person') class Workpackage(_GLSQLObject): name = sqlobject.StringCol() projects = sqlobject.RelatedJoin('Project') class Person(_GLSQLObject): firstName = sqlobject.StringCol() projects = sqlobject.RelatedJoin('Project') if __name__ == '__main__': Project.createTable() Workpackage.createTable() Person.createTable() person1 = Person(firstName="Person One") proj1 = Project(name="Project One", leader=person1) person1.addProject(proj1) print person1.projects print proj1.workpackages print proj1.steeringCommittee Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |