On Oct 16, 2007, at 1:30 PM, [EMAIL PROTECTED] wrote:

>
> Hi everybody!
>
> I've got a schema with a combined 1:n:1 + m:n relation.
> In detail, I have the entities "user" and "event" and the relation
> "participation".
> That leads to 1:n user->participation, n:1 participation->event, and
> m:n user->event:
>
>  [user] 1 -- * [participation] * -- 1 [event]
>    * \_________________________________/ *
>
> Now the (assumed) bug is that the participation mapping only works
> correctly after saving, flushing, clearing and retrieving the objects
> (output only included where relevant):
>
>  u = User(); u.name = "test user"
>  e = Event(); e.title = "test event"
>  u.events.append(e)
>  u.participations
>  [] #empty!
>  e.participations
>  [] #empty!
>
>  session.save(u); session.save(e); session.flush(); session.clear()
>  u = session.query(User).get(1)
>  e = session.query(Event).get(1)
>  [<__main__.Participation object at 0x01035F50>] # not empty!
>  e.participations
>  [<__main__.Participation object at 0x01035F50>] # not empty!
>
> I think that the results should be identical before and after save/
> flush/clear/query.
> Is this assumption wrong?
> Am I really supposed to save/flush/clear/query my objects to get the
> correct mappings?
> Or is this a bug?


the issue is you are using the participation_table as both a mapped  
table as well as an association table, which is not recommended; SA  
performs mapping operations with the table in two totally different  
ways which are not really compatible with each other (i.e., removing  
an Event from a User can leave existing Participation objects in your  
session in an invalid state).  the advised pattern here is the  
"association object" pattern described in the docs:  http:// 
www.sqlalchemy.org/docs/04/ 
mappers.html#advdatamapping_relation_patterns_association



--~--~---------~--~----~------------~-------~--~----~
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