if the collection is one-to-many, then the example below is impossible  
from a relational standpoint; the identity "item1" corresponds to a  
primary key value so a single item cannot appear multiple times.

If the collection is a many-to-many, SQLA's implementation of m2m  
using a plain relation() with a "secondary" table assumes that rows  
within the association table are unique with respect to the foreign  
keys (in effect the foreign keys of the association table form a  
composite primary key).

To achieve a list of items where the same item may be repeated in the  
colleciton you'd map List.items to an explicitly mapped association  
class with its own primary key column that is distinct from the  
association between parent and child (see the "association object"  
examples in the documentation).   The association proxy extension,  
also described in the documentation, may optionally be used to  
decrease the verbosity of navigating from list->items->item.element.


On Sep 9, 2008, at 5:34 AM, mraer wrote:

>
> class List:
> pass
>
> class Item:
> pass
>
> list = List()
> item1 = Item()
> item2 = Item()
>
> list.items.append(item1)
> list.items.append(item2)
> list.items.append(item1)
>
> session.add(list)
> session.commit()
>
> after it i have only one item1 in list.
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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