Hi,

  how should I configure a mapper that represents a join between two tables
  so that inserting a new object writes the foreign key between the two in
  the proper way?

      class Table_a(Base):
          __tablename__ = 'a' 
          id = Column(Integer, primary_key=True)
          description = Column(String(100))

      class Table_b(Base):
          __tablename__ = 'b'

          idb = Column(Integer, primary_key=True)
          a_id = Column(ForeignKey(Table_a.id), nullable=False)

      a_table = Table_a.__table__
      b_table = Table_b.__table__

      class MyJoin(object): pass

      m = mapper(MyJoin, a_table.join(b_table))

      j = MyJoin()
      j.description = 'xxx'

      sess.add(j)

      Base.metadata.bind.echo = True
      sess.commit()


2009-05-05 12:41:52,346 INFO sqlalchemy.engine.base.Engine.0x...7acL BEGIN
2009-05-05 12:41:52,347 INFO sqlalchemy.engine.base.Engine.0x...7acL INSERT 
INTO a (description) VALUES (?)
2009-05-05 12:41:52,347 INFO sqlalchemy.engine.base.Engine.0x...7acL ['xxx']
2009-05-05 12:41:52,348 INFO sqlalchemy.engine.base.Engine.0x...7acL INSERT 
INTO b (a_id) VALUES (?)
2009-05-05 12:41:52,348 INFO sqlalchemy.engine.base.Engine.0x...7acL [None]
2009-05-05 12:41:52,348 INFO sqlalchemy.engine.base.Engine.0x...7acL ROLLBACK

   
    Is it possible to prepare the mapper so that a_id gets the value that
    the first object got as id?

thanks
sandro
*:-)

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