syntax to add custom constraints to entities?

0 views
Skip to first unread message

Victor Ng

unread,
Apr 27, 2007, 9:45:19 AM4/27/07
to SQLElixir
Is there a less ugly way to declare uniqueness constraints for the
following example?

6 class Bar(Entity):
7 has_field('id', Integer(), primary_key=True)
8
9 class Foo(Entity):
10 belongs_to('bar', of_kind='Bar')
11 has_field('id', Integer(), primary_key=True)
12 Foo._descriptor.add_constraint(UniqueConstraint('bar_id', 'id'))

I read through my copy of the elixir source and I didn't see anywhere
that the EntityMeta would pick up constraint declarations.

vic

Gaetan de Menten

unread,
Apr 27, 2007, 9:56:25 AM4/27/07
to sqle...@googlegroups.com

You can use the "using_table_options" statement for that.

Here is an excerpt from the TestTableOptions test in:
http://elixir.ematia.de/svn/elixir/trunk/tests/test_options.py

class Person(Entity):
has_field('firstname', Unicode(30))
has_field('surname', Unicode(30))

using_table_options(UniqueConstraint('firstname', 'surname'))

--
Gaëtan de Menten
http://openhex.org

Jonathan LaCour

unread,
Apr 27, 2007, 10:32:30 AM4/27/07
to sqle...@googlegroups.com
Gaetan de Menten wrote:

>> Is there a less ugly way to declare uniqueness constraints for the
>> following example?
>>

>> [snip, snip example...]


>>
>
> You can use the "using_table_options" statement for that.
>

FYI, I just added something about this to the FAQ. It might be a good
idea to start thinking about how to make the FAQ available on the
website, or we could follow through and put up a Wiki.

Any ideas?

--
Jonathan LaCour
http://cleverdevil.org

Victor Ng

unread,
Apr 27, 2007, 12:11:30 PM4/27/07
to SQLElixir
doh! I forgot to grep the tests directory. Thanks for the help!

vic

Reply all
Reply to author
Forward
0 new messages