Oh, thanks for the pointer. There's so much to read and learn being new to SQLAlchemy... Sorry for bugging.

On Fri, 05 Mar 2010 15:49:03 +0100, Michael Bayer <[email protected]> wrote:

Sebastian Elsner wrote:
Hello,

I have an association object declaratively with three primary keys, but on
insert, the first (id) is not autoincremented. Please see test the code
below

known sqlite limitation, described at

http://www.sqlalchemy.org/docs/reference/dialects/sqlite.html?highlight=sqlite#auto-incrementing-beahvior





from sqlalchemy import create_engine, Column,Integer, String, ForeignKey
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import sessionmaker,relation, backref

engine = create_engine("sqlite:///:memory:",echo=False)
Base=declarative_base()


class Child(Base):

     __tablename__="Child"

     id=Column(Integer,primary_key=True)

class Association(Base):

     __tablename__="Association"

     id=Column(Integer,primary_key=True)

     parent_id=Column(Integer,ForeignKey("Parent.id"),primary_key=True)
     child_id=Column(Integer,ForeignKey("Child.id"),primary_key=True)

     child=relation(Child,backref="parents")

     data=Column(String(32))

     def __init__(self):
         self.data="some text"

class Parent(Base):
     __tablename__="Parent"

     id=Column(Integer, primary_key=True)

     children=relation(Association,backref=backref("parent"))

Base.metadata.create_all(engine)
Session=sessionmaker(bind=engine)
session = Session()

p=Parent()
a=Association()
a.child=Child()
p.children.append(a)

session.add(p)
session.query(Parent).all()


I need the id for another 1:n realtion with the association object. What
am I missing here?


Thanks

Sebastian

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





--
Sebastian Elsner    -    pipeline td   -   r i s e |  fx

t:  +49 30 20180300                 [email protected]
c:  +49 175 3365739                       www.risefx.com

r i s e |  fx  GmbH
Schlesische Strasse 28 Aufgang B, 10997 Berlin
Geschäftsführer: Sven Pannicke, Robert Pinnow

Handelsregister Berlin HRB 106667 B

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

Reply via email to