On Jun 10, 10:34 am, Malthe Borch <[EMAIL PROTECTED]> wrote:
> I have an issue with SQLAlchemy planning to execute insertion tasks in
> the wrong order.
>
> Basically, I have a utility table "Relations" which is used to maintain
>   ordered list relations:
>
> table = rdb.Table(
>    'relation',
>    metadata,
>    rdb.Column('id', rdb.Integer, primary_key=True, autoincrement=True),
>    rdb.Column('left', rdb.String(length=32),
>       rdb.ForeignKey("soup.uuid"), index=True),
>    rdb.Column('right', rdb.String(length=32),
>       rdb.ForeignKey("soup.uuid")),
>    rdb.Column('order', rdb.Integer, nullable=False))
>
> Now, I append a new, transient object to such an ordered list. That
> means that SQLAlchemy would make two inserts. The problem is that the
> tasks are ordered such that the *relation* is inserted before the object
> that is the target of the relation!
>
> This obviously raises an IntegrityError, since the foreign key
> constraint is not satisfied.
>
> My question is then: How do I tell SQLAlchemy to order them correctly?
>
> \malthe

A self-referential relationship, when configured as many-to-one,
requires the "remote_side" argument to indicate this, as described in
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relation_selfreferential
.  Otherwise it defaults to "one-to-many".

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to