Ah, stupid me. Thanks!

 

From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On
Behalf Of Michael Bayer
Sent: Monday, May 27, 2013 6:26 PM
To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Self-referencing row and CircularDependencyError

 

 

On May 27, 2013, at 5:16 AM, Alexey Vihorev <viho...@gmail.com> wrote:





Hi!

 

Can I handle this situation properly, if at all?

 

Base = declarative_base()

 

class Person(Base):

    __tablename__ = 'persons'

    id = Column(Integer, primary_key=True)

    best_friend_id = Column(Integer, ForeignKey('persons.id'))

    best_friend = relationship('Person', remote_side = 'Person.id')

 

Base.metadata.create_all(sa_engine)

 

person = Person()

person.best_friend = person #<<< problematic self-reference

s.add(person)

s.commit() #sqlalchemy.exc.CircularDependencyError: Circular dependency
detected.

 

it will work with post_update

 

class Person(Base):

    __tablename__ = 'persons'

    id = Column(Integer, primary_key=True)

    best_friend_id = Column(Integer, ForeignKey('persons.id'))

    best_friend = relationship('Person', remote_side = 'Person.id',
post_update=True)

 

 

 

 





 

-- 
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to <mailto:sqlalchemy+unsubscr...@googlegroups.com>
sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to  <mailto:sqlalchemy@googlegroups.com>
sqlalchemy@googlegroups.com.
Visit this group at  <http://groups.google.com/group/sqlalchemy?hl=en>
http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit  <https://groups.google.com/groups/opt_out>
https://groups.google.com/groups/opt_out.
 
 

 

-- 
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to  <mailto:sqlalchemy+unsubscr...@googlegroups.com>
sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to  <mailto:sqlalchemy@googlegroups.com>
sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to