foreign key reference between the models of two different TurboGears projects?

3 views
Skip to first unread message

JV

unread,
Nov 4, 2008, 7:16:47 AM11/4/08
to sqlalchemy
Hi

How can I have a foreign key reference between the models of two
different TurboGears projects?
I am using sqlalchemy.

JV

Michael Bayer

unread,
Nov 4, 2008, 8:19:37 AM11/4/08
to sqlal...@googlegroups.com
either share the same MetaData object across those two models, or
place the actual Column object instead of a string in the ForeignKey()
constructor.

JV

unread,
Nov 4, 2008, 8:40:40 PM11/4/08
to sqlalchemy
Michael

Can you elaborate a bit on how to do each of the thing you said -
metadata sharing between 2 separate Turbogears projects and placing
the actual column in the ForeignKey constructor, instead of string
'table.column.id'.

I read your earlier discussion
http://groups.google.com/group/sqlalchemy/browse_thread/thread/4db84b9f07236fed/5fa2ee7131798264?lnk=gst&q=metadata+sharing#5fa2ee7131798264
but I am still not clear on how to share the metadata. The only way I
can think of is to import the metadata object from one model1 to
model2, but that shall require the two pkgs to be present in fixed
relative positions. I don't see a common module where I can keep the
metadata object and use it in either pkg.

JV

JV

unread,
Nov 5, 2008, 1:09:42 AM11/5/08
to sqlalchemy
I got a solution. Thanks to Michael. Here is what he suggested.

*****

You use the Column object:

from myproject.model import sometable

someothertable = Table('someothertable', metadata, Column('foobar',
Integer, ForeignKey(sometable.c.foobar))


as you can see the common theme in both cases is that one project has
to get at the model of the other one - either the metadata object, or
the table/column object (you can get at the metadata of any table
using Table.metadata). The problem you're laying out is essentially
one of one project having a dependency on the other, so unless you
wanted to redefine the same Table objects as are in the first project
as in the second project, you'd have an import dependency from the
first one to the second.

as far as importing modules across Turbogears projects, you'd have to
ask on their list how that might be accomplished.
*****

Both the ways work. :)
Just that I will have to maintain a fixed relative path between the
two packages and append the location of one pkg to sys.path while
accessing its model from the other.


JV


On Nov 5, 6:40 am, JV <JaiVikram.Ve...@gmail.com> wrote:
> Michael
>
> Can you elaborate a bit on how to do each of the thing you said -
> metadata sharing between 2 separate Turbogears projects and placing
> the actual column in the ForeignKey constructor, instead of string
> 'table.column.id'.
>
> I read your earlier discussionhttp://groups.google.com/group/sqlalchemy/browse_thread/thread/4db84b...
Reply all
Reply to author
Forward
Message has been deleted
0 new messages