ok that ticket is fixed in the trunk

On Mar 19, 2007, at 5:54 AM, Alexandre CONRAD wrote:

> from sqlalchemy import *
>
> meta = DynamicMetaData()
>
> # Sites
> site_table = Table('sites', meta,
>     Column('id', Integer, primary_key=True),
>     Column('name', Unicode(20), nullable=False, unique=True),
>     Column('email', Unicode(100)),
> )
>
> class Site(object):
>     pass
>
> site_mapper = mapper(Site, site_table,
>     order_by=site_table.c.name,
> )
>
>
> # Options
> option_table = Table('options', meta,
>     Column('id', Integer, primary_key=True),
>     Column('name', Unicode(20), unique=True, nullable=False),
>     Column('description', Unicode(40)),
> )
>
> options_has_sites = Table('options_has_sites', meta,
>     Column('id_site', None, ForeignKey('sites.id'), primary_key=True),
>     Column('id_option', None, ForeignKey('options.id'),  
> primary_key=True),
> )
>
> class Option(object):
>     def __repr__(self):
>         return "Option: %s" % repr(self.name)
>
> option_mapper = mapper(Option, option_table,
>     properties={
>         'sites':relation(Site, backref="options",  
> secondary=options_has_sites, cascade="save-update"),
>     },
>     order_by=option_table.c.name,
> )
>
> meta.connect("sqlite://", echo=True)
> meta.create_all()
>
> # Make session.
> session = create_session()
>
> # Inject sites and options.
> for i in range(1, 4):
>     o = Option()
>     o.name, o.description = "opt%d" % i, "This is option %d" % i
>     session.save(o)
>     s = Site()
>     s.name, s.email = "site%d" % i, "[EMAIL PROTECTED]" % i
>     session.save(s)
>
> session.flush()
> session.clear()
>
> print """\n### Now, let's query for site 1."""
> s = session.query(Site).get(1)
> opts = session.query(Option).select()
> print """\n### Add options from 1 to 3 to the site."""
> s.options = opts[0:3] # Put option 1, 2 and 3
> session.flush()
> session.clear()
>
> print """\n### Now, let's query for site 1 again."""
> s = session.query(Site).get(1)
> print """\n### Check the site has the options 1, 2 and 3."""
> print s.options, "!!!!!!!we should have opt 1, 2 and 3 here!!!!!!!"
> session.clear()
>
> print """\n### If it has, we should have pairs of (id_site, id_opt)  
> in options_has_sites."""
> print options_has_sites.select().execute().fetchall(), "!!!!!!!we  
> should have 3 pairs here!!!!!!!"
>
> print """\n### Now, let's query for option 1."""
> o = session.query(Option).get(1)
> print """\n### Now remove option 1."""
> session.delete(o)
> session.flush()
> session.clear()
>
> print """\n### Now, let's query for site 1 again."""
> s = session.query(Site).get(1)
> print """\n### Check what options has the site. Option 1 should be  
> removed from sites."""
> print s.options, "!!!!!!!!!we should only have opt2 and opt3 in  
> here!!!!!!!!!!!!!"
> session.clear()
>
> print """\n### Now check that the row (id_site, id_opt) for option  
> 1 should be removed from table "options_has_sites"."""
> print options_has_sites.select().execute().fetchall(), "!!!!!!!we  
> should only have 2 pairs now that opt1 was removed!!!!!!!"
>
> print """\n### Let's query for site 1."""
> s = session.query(Site).get(1)
> print """\n### Now let's delete the site."""
> session.delete(s)
> session.flush()
> session.clear()
>
> print """\n### We should still have option 2 and 3, even if the  
> site was deleted."""
> print session.query(Option).select()
>
> print """\n### The rows (id_site, id_opt) for option 2 and 3 of the  
> site should be removed from "options_has_sites"."""
> print options_has_sites.select().execute().fetchall(), "!!!!!We  
> want this cleaned up and empty now that we have removed the site.  
> How to do that ??!!!!!!!!!"


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