Thanks Michael, I'll have a look over this !!

Bob, thanks also for your help, however, I'm not able to use the
code... maybe the indention is wrong here or I don't know... I was
able to execute the function, but even by putting a print as the first
line of the function, nothing got printed out, weird... (maybe my lack
of skills using python, yet :P)

On Aug 27, 3:11 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> I'm not fluent with Elixir, but here is a sample script using  
> declarative and SQLite (another database that has a very casual notion  
> of foreign keys) which demonstrates the correct behavior.    First  
> convert this script to Elixir (and also to 0.4 if needed, this script  
> is made against 0.5) and use with your MySQL database, then work  
> backwards towards your code to see at what point the "0" starts  
> popping up.
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
> from sqlalchemy.ext.declarative import declarative_base
>
> engine = create_engine('sqlite://', echo=True)
> Base = declarative_base()
>
> class PublicationElement(Base):
>      __tablename__ = 'publication'
>      publication_id = Column(Integer, primary_key=True)
>      name = Column(Unicode(255))
>
> class SectionElement(Base):
>      __tablename__ = 'section'
>      section_id = Column(Integer, primary_key=True)
>      publication_id = Column(Integer,  
> ForeignKey('publication.publication_id'), nullable=False)
>      publication = relation('PublicationElement', cascade="all, delete-
> orphan", backref='sections')
>      name = Column(Unicode(255))
>
> Base.metadata.create_all(engine)
>
> Session = sessionmaker(bind=engine)
>
> sec1 = SectionElement(name='s1',  
> publication=PublicationElement(name='p1'))
> sess = Session()
> sess.add(sec1)
> sess.commit()
>
> assert sess.query(SectionElement).one().publication.name == 'p1'
>
> sess.delete(sec1)
> sess.commit()
>
> assert engine.execute("select count(1) from publication").scalar() == 0
> assert engine.execute("select count(1) from section").scalar() == 0
--~--~---------~--~----~------------~-------~--~----~
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