if youre using an association table that has other state in it, you  
should probably use the "association object" pattern:

        http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_association

however, ive just noticed the latest trunk (which I dont think youre  
using) has an issue with setting the blank list, so im fixing that,  
and also ill look and see why the default many-to-many operation  
seems to track every column in the table instead of just the ones  
that relate.

On Jun 15, 2006, at 12:49 PM, Steve Zatz wrote:

> I may be making a mistake but in the following situation in which
> there is a many-to-many relationship if the table containing the
> relationships has columns in addition to the Foreign Key columns then
> trying to delete relationships by doing:
>
> item.keywords = []
>
> does not work. I don't know SQL well enough to know whether you should
> not have any other columns in the relationship table but this doesn't
> seem like a reasonable constraint. The delete is issued with the
> additional column values having values of None but if there is data in
> those columns, the delete does not take place.  Perhaps this is an
> expected feature but it doesn't quite make sense to me.
>
> The example is below:
>
> ---------------------------------------------------------------------- 
> ------------------------------------------------
>
>
> item_table = Table('item',metadata,
>               Column('id', Integer, primary_key=True),
>               Column('name',String(150)),
> )
>
> keyword_table = Table('keyword', metadata,
>                  Column('id', Integer, primary_key=True),
>                  Column('name', String(25), nullable=False),
> )
>
> itemkeyword_table = Table('item_keyword', metadata,
>                       Column('item_id', Integer,ForeignKey('item.id'),
> nullable=False),
>                       Column('keyword_id', Integer,
> ForeignKey('keyword.id'), nullable=False),
>                       Column('flag', Boolean, default=True),  #<--
> additional column
> )
>
>
> class Item_a(object):
>     def __init__(self, name):
>         self.name = name
>
>
> class Keyword_a(object):
>     def __init__(self, name):
>         self.name = name
>
> mapper(Keyword, keyword_table, properties = dict(items =
> relation(Item, secondary=itemkeyword_table, lazy=False),))
> mapper(Item, item_table, properties = dict(keywords =
> relation(Keyword, secondary=itemkeyword_table, lazy=False),))
>
> item = Item("test)
> keyword = Keyword("key_for_test")
> item.keywords.append(keyword)
> item.keywords = []
> #the above will not remove the corresponding rows in  
> itemkeyword_table because
> #there is non-null data in some of the columns
>
>
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to