Re: [SQLObject] RelatedJoin to same table -- possible?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Peter H. <tph...@gm...> - 2005-08-19 20:29:54
|
Hi Oleg, Thanks for the quick reply. On 8/19/05, Oleg Broytmann <ph...@ma...> wrote: > On Wed, Aug 17, 2005 at 07:08:44PM -0400, Peter Herndon wrote: > > CREATE TABLE partners (partner_id INTEGER PRIMARY KEY, company_id > > INTEGER, company_id INTEGER); > > > > Both foreign key columns are named the same. Is this a bug in > > SQLObject? Is there a better way to accomplish my goal? >=20 > Not a bug, but deficiency. SQLObject has problems handling self-joins. >=20 > You have to create tables by hands, and use sqlobject.sqlbuilder.Alias > and related helpers to build SQL queries. >=20 I think I found a way around it. I create two classes, Companies and Partners, as follows: class Companies(SQLObject): partners =3D MultipleJoin('Partners') partnerOf =3D MultipleJoin('Partners') class Partners(SQLObject): company_id1 =3D ForeignKey('Companies') company_id2 =3D ForeignKey('Companies') This way is somewhat painful to write, and I haven't actually used it in practice yet, but it compiles and runs, and looks like it will do what I need. Any thoughts? ---Peter |