>
> In case of RelatedJoins SQLObject deletes objects from the
intermediate
> table itself because the table can be hidden from the user at all - it is
> usually automatically created and maintained.
>
Ok, I just realized that my example was bad. This one's better:
class Top(sqlobject.SQLObject):
a = sqlobject.SQLMultipleJoin('A')
class AB(sqlobject.SQLObject):
a = sqlobject.ForeignKey('A', cascade = True)
b = sqlobject.ForeignKey('B', cascade = True)
class A(sqlobject.SQLObject):
top = sqlobject.ForeignKey('Top', cascade = True)
b = sqlobject.RelatedJoin('B', intermediateTable = AB.sqlmeta.table,
createRelatedTable = False)
class B(sqlobject.SQLObject):
a = sqlobject.RelatedJoin('A', intermediateTable = AB.sqlmeta.table,
createRelatedTable = False)
Top.createTable(ifNotExists = True)
A.createTable(ifNotExists = True)
B.createTable(ifNotExists = True)
AB.createTable(ifNotExists = True)
[a.destroySelf() for a in A.select()]
[b.destroySelf() for b in B.select()]
[ab.destroySelf() for ab in AB.select()]
top = Top()
a1 = A(top = top)
a2 = A(top = top)
a3 = A(top = top)
a4 = A(top = top)
b1 = B()
b2 = B()
b3 = B()
b4 = B()
a1.addB(b1)
a1.addB(b2)
a2.addB(b1)
a2.addB(b2)
a2.addB(b3)
a3.addB(b4)
a4.addB(b2)
a4.addB(b4)
# Slow:
top.destroySelf()
# Fast:
# Top.deleteBy(id = top.id)
The first destroy statement results in these queries:
1/Select : SELECT a.id, a.top_id FROM a WHERE ((a.top_id) = (5))
2/Query : DELETE FROM ab WHERE a_id=17
1/Select : SELECT ab.id, ab.a_id, ab.b_id FROM ab WHERE ((ab.a_id) =
(17))
2/Query : DELETE FROM ab WHERE a_id=17
1/Query : DELETE FROM a WHERE id = (17)
2/Query : DELETE FROM ab WHERE a_id=18
1/Select : SELECT ab.id, ab.a_id, ab.b_id FROM ab WHERE ((ab.a_id) =
(18))
2/Query : DELETE FROM ab WHERE a_id=18
1/Query : DELETE FROM a WHERE id = (18)
2/Query : DELETE FROM ab WHERE a_id=19
1/Select : SELECT ab.id, ab.a_id, ab.b_id FROM ab WHERE ((ab.a_id) =
(19))
2/Query : DELETE FROM ab WHERE a_id=19
1/Query : DELETE FROM a WHERE id = (19)
2/Query : DELETE FROM ab WHERE a_id=20
1/Select : SELECT ab.id, ab.a_id, ab.b_id FROM ab WHERE ((ab.a_id) =
(20))
2/Query : DELETE FROM ab WHERE a_id=20
1/Query : DELETE FROM a WHERE id = (20)
2/Query : DELETE FROM top WHERE id = (5)
1/Query : DELETE FROM top WHERE id = 5
whereas the second destroy statement produces just
1/Query : DELETE FROM top WHERE id = 4
It seems like sqlobject is iterating though all of top's siblings in order
to destroy them. In case I have many of these siblings, the DB is able to
perform this operations magnitudes faster than sqlobject. Is deleteBy() the
preferred (the only?) way for doing just this?
Thanks,
Bernhard
___________________________________________________________________
Disclaimer:
Diese Mitteilung ist nur fuer die Empfaengerin / den Empfaenger bestimmt.
Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird,
bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden und
anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige Kopien
zu vernichten bzw. zu loeschen. Der Gebrauch der Information ist verboten.
This message is intended only for the named recipient and may contain
confidential or privileged information.
If you have received it in error, please advise the sender by return e-mail
and delete this message and any attachments. Any unauthorised use or
dissemination of this information is strictly prohibited.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss