From: Robin M. <rob...@gm...> - 2005-10-11 17:46:06
|
On 10/11/05, Luke Opperman <lu...@me...> wrote: > I'll agree on MultipleJoin, although the one nice thing would be if in th= e > default case it was automatically created, or at least the opposing colum= n > name was auto - in which case the explicit MultipleJoin is just for alter= nate > naming and resolving the case of multiple FKs to the same class. But we'r= e not > doing that now, so no difference from the manual select. I don't think we'd need MultipleJoin even in the case of resolving multiple FKs to the same class, if give ForeignKey a parameter to specify the name of the auto-created attribute in the other class. Something like this: class Factory(SQLObject): location =3D StringCol() class Widget(SQLObject): barcode =3D StringCol() produced_in =3D ForeignKey("Factory", related_name=3D"widgets_produced"= ) shipped_to =3D ForeignKey("Factory", related_name=3D"widgets_received") acme =3D Factory(location=3D"ACME Corp. Headquarters") foo =3D Factory(location=3D"Foo, Inc. Manufacturing") widget1 =3D Widget(barcode=3D"123", produced_in=3Dacme, shipped_to=3Dfoo) widget2 =3D Widget(barcode=3D"456", produced_in=3Dfoo, shipped_to=3Dacme) print list(acme.widgets_produced) # prints [<Widget 1 barcode=3D"123" ...>= ] print list(foo.widgets_received) # prints [<Widget 1 barcode=3D"123" ...>] print list(foo.widgets_produced) # prints [<Widget 2 barcode=3D"456" ...>] print list(acme.widgets_received) # prints [<Widget 2 barcode=3D"456" ...>= ] Factory.widgets_produced and Factory.widgets_received could still be automatically-created MultipleJoins like we have now, but I think I'd also rather see them as auto-created select() calls, as Ian suggested _get_foos() should be in his original email of the thread. I'm not entirely sure about "related_name" as the name of the keyword argument. That's what Django uses, because they refer to ForeignKeys as "Relations". Another name might be better for the terminology SQLObject uses. Thoughts? -- Robin Munn Rob...@gm... GPG key 0xD6497014 |