As simple as that... thanks!

On 31 oct, 01:32, Michael Bayer <[EMAIL PROTECTED]> wrote:
> oh sorry, I was on autopilot.  Two different classes indeed.
>
> If you aren't using ForeignKey, the foreign_keys argument points to  
> the column or columns that would have ForeignKey on them, so the  
> argument should be the same in both directions on the relation:
>
>     parent          = relation(Parent,
>                            primaryjoin=id_parent==Parent.id,
>                            foreign_keys=[id_parent],
>                            backref=backref('children',
>                                foreign_keys=[id_parent],
>                                cascade='all, delete-orphan',
>                                passive_deletes=False))
>
> On Oct 30, 2008, at 6:58 PM, GustaV wrote:
>
> > rom zope.sqlalchemy import ZopeTransactionExtension
> > from sqlalchemy.orm import scoped_session, sessionmaker, eagerload
> > from sqlalchemy import MetaData
> > from sqlalchemy.orm.interfaces import SessionExtension
> > from sqlalchemy.ext.declarative import declarative_base
> > from sqlalchemy import Table, Column, types
> > from sqlalchemy import ForeignKey, UniqueConstraint
> > from sqlalchemy.orm import relation, backref, synonym
> > from sqlalchemy import select, func
>
> > maker = sessionmaker(autoflush=True, autocommit=False,
> >                     extension=[ZopeTransactionExtension()])
> > DBSession = scoped_session(maker)
> > DeclarativeBase = declarative_base()
>
> > class Parent(DeclarativeBase):
> >    __tablename__   = 'parent'
> >    id              = Column('id', types.Integer, primary_key=True,
> > nullable=False)
>
> > class Child(DeclarativeBase):
> >    __tablename__   = 'child'
> >    id              = Column('id', types.Integer, primary_key=True,
> > nullable=False)
> >    id_parent       = Column('id_parent', types.Integer,
> > nullable=True)
> >    parent          = relation(Parent,
> >                           primaryjoin=id_parent==Parent.id,
> >                           foreign_keys=[Parent.id],
> >                           backref=backref('children',
> >                               foreign_keys=[id_parent],
> >                               cascade='all, delete-orphan',
> >                               passive_deletes=False))
>
> > p = Parent()
> > c = Child()
> > p.children.append(c)
> > DBSession.add(p)
> > DBSession.flush()
--~--~---------~--~----~------------~-------~--~----~
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