[storm] Compound foreign key

James Henstridge james at jamesh.id.au
Tue Aug 26 10:06:50 BST 2008


On Tue, Aug 26, 2008 at 4:05 PM, Gerdus van Zyl <gerdusvanzyl at gmail.com> wrote:
> How do I create a compound foreign key referenceset?
>
> I want a invoice detail refset on the invoiceBase class.
>
> Currently I use a uuid as a surrogate foreign key but I worry about
> possible performance when the database grows large.
> invoicedetail = ReferenceSet(invoiceBase.ck, invoicedetailBase.ck)
>
> What is the lists opinion on using uuid's as primary and foreign keys?

References and reference sets are created between columns on tables
rather than the tables themselves, so compound keys shouldn't cause a
problem.  For example:

    class Foo(object):
        __storm_table__ = "foo"
        __storm_primary__ = "pk1", "pk2"
        pk1 = Int()
        pk2 = Int()

    class Bar(object):
        __storm_table__ = "bar"
        id = Int(primary=True)
        pk1 = Int()
        pk2 = Int()
        foo = Reference((pk1, pk2), (Foo.pk1, Foo.pk2))

You can do similar for reference sets in the other direction.

James.



More information about the storm mailing list