Hi all

With  SA 1.0.4 I can delete rows that i could not delete with SA 0.9.3 .

MODEL.

Base = declarative_base()
class Node(Base):
    __tablename__ = 'node'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('node.id'))
    data = Column(String(50))
    children = relationship("Node",
                backref=backref('parent', remote_side=[id],
                ),lazy="dynamic"                        
            )

e = create_engine('postgresql+psycopg2://*****/test')
Base.metadata.create_all(e)
session = Session(e)

QUERY AND DATA  ARE:

query = session.query(
                Node.id,
                Node.parent_id,
                Node.data)
results  = query.all()
print results

[(1, None, u'parent'), (2, 1, u'child')]


NOW I TRY TO DELETE THE PARENT:


parent = session.query(Node).get(1)
print parent
session.delete(parent)
session.commit()
results  = query.all()
print results


RESULT with SA 0.9.3

sqlalchemy-0.9.3-py2.7.egg\sqlalchemy\engine\default.pyc in do_execute(self, 
cursor, statement, parameters, context)    423     424     def do_execute(self, 
cursor, statement, parameters, context=None):--> 425         
cursor.execute(statement, parameters)    426     427     def 
do_execute_no_params(self, cursor, statement, context=None):
IntegrityError: (IntegrityError) update or delete on table "node" violates 
foreign key constraint "node_parent_id_fkey" on table "node"
DETAIL:  Key (id)=(1) is still referenced from table "node".
 'DELETE FROM node WHERE node.id = %(id)s' {'id': 1}



RESULT with SA 1.0.4: 

====================

<__main__.Node object at 0x056BC5B0>
[(2, None, u'child')]


The parent is deleted and node.parent_id is set to null.


What should I change in the relationship or model to have in SA 1.0.4 the same 
behavior  as in SA 0.9.3 ?


Regards 

G







-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to