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

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