On 4/27/07, Victor Ng <[EMAIL PROTECTED]> wrote:
>
> Google Groups won't let me reply to the existing thread. Darn wonky
> AJAX.
>
> The UniqueConstraint fails inside SQLAlchemy when referencing a
> foreign key field.
I didn't think about that when I saw your example but it was to be
exepected. It's caused by a known problem: columns created by
belongs_to relationships are not available when the entity is defined
but rather afterwards when the relation is defined. And this is done
only when the target of the relation is defined. I'll fix this problem
hmm... well... whenever I'll fix it :)
> So something like this:
>
> 30 class Foo(Entity):
> 31 belongs_to('bar', of_kind='Bar')
> 32 has_field('id', Integer(), primary_key=True)
> 33 using_mapper_options(extension=FooME())
> 34 using_table_options(UniqueConstraint('bar_id', 'id'))
>
> throws this error:
[...]
> The workaround is to just push out the UniqueConstraint outside of the
> class definition and do:
>
> Foo._descriptor.add_constraint(UniqueConstraint(...))
This might not work in all case. I mean it'll only work if the class
targeted by your foreign key ("Bar" in your example) is defined before
you add the unique constraint.
--
Gaƫtan de Menten
http://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---