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


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