its the backref.  as a temporary workaround you can remove it for  
merge() to function properly.  fix wil be out today and very possible  
release 0.4.3 will be today for this.


On Jan 30, 2008, at 6:14 AM, Paul-Michael Agapow wrote:

> from sqlalchemy import *
>       from sqlalchemy.orm import *
>
>       metadata = MetaData()
>
>       class Biosequence (object):
>               pass
>
>       class Annotation (object):
>               pass
>
>       table_biosequences = Table ('biosequences', metadata,
>               Column ('identifier', Integer(), primary_key=True),
>               Column ('dummy', String(16)),
>       )
>
>       table_seqannotations = Table ('seqannotations', metadata,
>               Column ('identifier', Integer(), primary_key=True),
>               Column ('biosequence_id', Integer(), ForeignKey  
> ('biosequences.identifier')),
>       )
>
>       mapper (Annotation, table_seqannotations)
>       mapper (Biosequence, table_biosequences,
>               properties={    
>                       'annotations':relation (
>                               Annotation,
>                               backref='biosequence_ref',
>                               lazy=False,
>                               cascade="all, delete, delete-orphan",
>                       ),
>               },
>       )
>
>       engine = create_engine ('sqlite:///', convert_unicode=True,
>               # echo=True,
>       )
>       sessionfactory = sessionmaker (bind=engine, autoflush=False,  
> transactional=False)
>       session = sessionfactory()
>       metadata.create_all (bind=engine, checkfirst=True)
>
>       # make an object with 3 'children'
>       bseq = Biosequence()
>       anns = [Annotation() for x in range (3)]
>       bseq.annotations = anns
>       print "Original num of anns:", len (bseq.annotations)
>
>       # the merged copy has 6 children
>       merge_bseq = session.merge (bseq)
>       session.flush()
>       print "Now num of anns still:", len (bseq.annotations)
>       print "Ids:", [x.identifier for x in bseq.annotations]
>       print "Merged copy num of anns:", len (merge_bseq.annotations)
>       print "Ids:", [x.identifier for x in merge_bseq.annotations]
>
>       # as does the return!
>       results = session.query (Biosequence)
>       print "Number of results", results.count()
>       returned_bseq = results.one()
>       print "Returned num of anns:", len (returned_bseq.annotations)
>       print "Ids:", [x.identifier for x in returned_bseq.annotations]
>
>       # make an new object with 3 children
>       bseq2 = Biosequence()
>       bseq2.annotations = [Annotation() for x in range (3)]
>       print "New obj num of anns:", len (bseq.annotations)
>       session.save_or_update (bseq2)
>       session.flush()
>
>       # and it works as expected
>       results = session.query (Biosequence)
>       print "Number of retreived objects", results.count()
>       returned_bseqs = results.all()
>       for item in returned_bseqs:
>               print "Returned num of anns:", len (item.annotations)
>               print "Ids:", [x.identifier for x in item.annotations]
>
>


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