the rows in the M2M table should be deleted automatically.    it  
*might* require that your instances are present in the session but  
its not supposed to.  can you make me a short test case for this  
one ?  its not the first time ive heard about it.

technically you can just put ON DELETE CASCADE on the tables too but  
id like to fix this issue.


On Mar 16, 2007, at 12:19 PM, Alexandre CONRAD wrote:

>
> Humm, this doesn't help as if a site is deleted, it deletes the  
> options
> that where related to that option.
>
> I want to be able to:
> - delete an option without deleting a site
> - delete a site without deleting an option
>
> just delete (clean up) the related rows inside the weak
> "options_has_sites" table.
>
> I just can't figure it out...
>
>
> Michael Bayer wrote:
>
>>
>> youd need to add some "delete" cascades to your relationship, maybe
>> on just the backref (using the backref() function), e.g.
>>
>> option_mapper = assign_mapper(ctx, Option, option_table,
>>       properties={
>>           'sites':relation(Site, backref=backref("options",
>> cascade="save-update, delete"),
>> secondary=options_has_sites, cascade="save-update"),
>>       },
>>       order_by=option_table.c.name,
>> )
>>
>>
>>
>> On Mar 16, 2007, at 10:38 AM, Alexandre CONRAD wrote:
>>
>>
>>> Hello,
>>>
>>> I have a many-to-many relation between an option table and a site
>>> table.
>>>
>>> Deleting an option correctly deletes the related rows in
>>> "options_has_sites" table.
>>>
>>> But when I delete a site, I have some orphan rows in the
>>> "options_has_sites" table. How can I avoid this ?
>>>
>>>
>>> # SITE TABLE -----------
>>> site_table = Table('sites', meta,
>>>     Column('id', Integer, primary_key=True),
>>>     Column('name', Unicode(20), nullable=False, unique=True),
>>> )
>>>
>>> class Site(object):
>>>     pass
>>>
>>> site_mapper = assign_mapper(ctx, Site, site_table,
>>>     order_by=site_table.c.name,
>>> )
>>>
>>>
>>> # OPTION TABLE ------------
>>> option_table = Table('options', meta,
>>>     Column('id', Integer, primary_key=True),
>>>     Column('name', Unicode(20), unique=True, nullable=False),
>>> )
>>>
>>> options_has_sites = Table('sites_has_options', meta,
>>>     Column('id_site', None, ForeignKey('sites.id'),
>>> primary_key=True),
>>>     Column('id_option', None, ForeignKey('options.id'),
>>> primary_key=True),
>>> )
>>>
>>> class Option(object):
>>>     pass
>>>
>>> option_mapper = assign_mapper(ctx, Option, option_table,
>>>     properties={
>>>         'sites':relation(Site, backref="options",
>>> secondary=options_has_sites, cascade="save-update"),
>>>     },
>>>     order_by=option_table.c.name,
>>> )
>>>
>>>
>>> Should I play with backref() ?
>>>
>>> Regards,
>>> -- 
>>> Alexandre CONRAD
>>>
>>>
>>>
>>
>>
>>>
>>
>>
>> --------------------------------------------------------------------- 
>> ------------------------------
>> Texte inséré par Platinum 2007:
>>
>>  S'il s'agit d'un mail indésirable (SPAM), cliquez sur le lien  
>> suivant pour le reclasser : http://127.0.0.1:6083/Panda? 
>> ID=pav_31913&SPAM=true
>> --------------------------------------------------------------------- 
>> ------------------------------
>>
>>
>
> -- 
> Alexandre CONRAD - TLV FRANCE
> Research & Development
>
>
> >


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