On Tue, Jul 15, 2014 at 3:09 PM, Calvin Chen <cheng.c...@gmail.com> wrote:
> Hi,
>
> I try to create a 'UserFavoriteTopic' table in sqlachemy that uses 'user_id'
> and 'topic_id' as primary key(unique togher).
>
> How should I implement this? Any suggestions would be appreciated.
>
> My current implementation:
> ===================================================
> class TopicFavorite(db.Model):
>     __table_args__ = (
>         db.UniqueConstraint('user_id', 'topic_id',
> name='uc_topic_favorite'),
>     )
>     user_id = db.Column(db.Integer, primary_key=True)
>     topic_id = db.Column(db.Integer, primary_key=True)
>
> ====================================================

I'm not sure I understand the question. I don't think you need the
UniqueConstraint at all - by putting "primary_key=True" on both
columns, the pairing is guaranteed to be unique anyway.

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to