Let me preface this by saying that I researched to the best of my abilities the answers to my following inquiries. I would not ask for help without first trying to investigate this on my own. Asking through this forum is the proverbial end of the line, so thanks for taking any time to read and respond.
I understand relational databases and have been bridging a knowledge gap with ORMs, using SQLAlchemy. I've struggled a bit while learning what exactly is going on in the ORM when ADDING new associations in a M to N relationship. My questions are related to SQL Alchemy ORM concepts: 1) Relationships 2) Association Object pattern 3) Association Proxy To help me grasp the concepts, I pieced together a working example of an M to N relation and drew a diagram showing the relationships. The scenario is of a very crude appointment scheduler that someone like a realtor may use to keep track of who is visiting what property. My attribute naming convention was chosen to facilitate our discussion. *Link: Github repo <http://www.github.com/dowwie/sqlalchemyillustrated>* There are two files of interest: - orm_associations.py -- a working example - "SQLAlchemy - Association Object Relations.pdf" -- contains a diagram of the M to N relationship in orm_associations.py In this example, a user can be added to a meeting OR a meeting can be added to a user using either of these association proxies: Meeting.attendees_proxy.append(User) or User.meetings_proxy.append(Meeting) These statements create the desired outcome-- a new Appointment record inserted into the association table and possibly a new user or meeting record if none already exist. I'd like to know what exactly is happening in the ORM when either of these statements is executed. For instance, what is the association_proxy creator doing? If I add a user to a meeting, the attendees_proxy creator is defined as follows: creator=lambda user: Appointment(appointment_user_relation=user)) The creator expression appears to be creating a new Appointment object, but then defines the RELATIONSHIP as a User object? I'm missing something here. No idea what is going on. It seems to be all a bit to automagical to me. Thanks Darin -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
