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