0

I've created a database in MySQL that has the following tables

Attachment
Sender
Recipient
Message
mr_link
ms_link
ma_link

Sender and Recipient are distinct tables of email addresses mr_link contains the ids of a message and its associated recipients (one entry per recipient per message)

ms_link has the ids of a message and its associated sender

ma_link has the ids of a message and its associated file(s)

I've recently discovered SQLAlchemy and like how it will make my queries, etc. more efficient.

What I'm looking to do now is convert this existing schema into tables with relationships, but my MySQL-fu and SQLAlchemy-fu are still in their early stages.

I've come here for guidance.

Thanks, Larry

4

1 に答える 1

1

You have one major choice in implementing your model in SA, which is between using the ORM and going with straight SQL constructs. This can be confusing at first, because they have similar methods and behaviors. At the outset as you dig in, it might be useful to think of them in terms of the classes you work with:

  • using the SQL i/f, you will work primarily with Tables
  • using the ORM, you will work primarily with your classes (Messages, Recipients, Senders,etc)

In either case, you are likely to find yourself first implementing your primary entities and then following through to set up the many-to-many relationships between them. SA does some great stuff, but it is pretty deep. I recommend giving yourself some time to work through the pieces.

To that end, I would recommend spending some time in the Object Relational Tutorial. The BlogPost/Keyword example in the Many-to-Many section has some useful characteristics in common with your use case and should give you a place to start from.

于 2012-08-14T19:41:09.747 に答える