[SQLObject] Fwd: [TurboGears] Re: How to create tables with cyclic references?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Kevin D. <da...@gm...> - 2005-10-02 19:30:35
|
Hi JP, I'm forwarding your message on to the SQLObject list for further review. Does your patch include unit tests? Kevin ---------- Forwarded message ---------- From: Jo=E3o Paulo Fernandes Farias <jpa...@gm...> Date: Oct 2, 2005 9:09 AM Subject: [TurboGears] Re: How to create tables with cyclic references? To: tur...@go... Hi! I've patched SQLObject to do late reference on creation of tables. It is no 100%, but it is a starting point. I've attached the patch. -- JP On 10/1/05, Ian Bicking <ia...@co...> wrote: > > Jo=E3o Paulo Fernandes Farias wrote: > > Hi! > > > > How do I create tables with cyclic references? > > > > As an example, suppose we have two classes: > > > > class A(SQLObject): > > b =3D ForeignKey('B') > > > > class B(SQLObject): > > a =3D ForeignKey('A') > > > > > > /me using turbogears... > > > > I issue a: turbogears-admin.py sql create > > > > It gives me some erros because it tries to create table A but B does no= t > > exists, so it cannot be referenced. > > > > My suggestion is: Create all tables and then issue all the "alter table > > add constraint" as necessary. > > This is kind of hard. Technically you can do it like: > > class A(SQLObject): > b =3D ForeignKey('B') > > class B(SQLObject): > pass > > def create(): > B.createTable() > A.createTable() > B.sqlmeta.addColumn(ForeignKey(name=3D'a', foreignKey=3D'A'), > changeSchema=3DTrue) > > > However, this won't work with sqlobject-admin (and thus > turbogears-admin.py). > -- Kevin Dangoor Author of the Zesty News RSS newsreader email: ki...@bl... company: http://www.BlazingThings.com blog: http://www.BlueSkyOnMars.com |