Hi,
I realized that mm functions weren't exactly what I need, because they
execute SQL statements right now instead of saving the changes at the next
commit.
I tried adding the bizContactlabel bizObject as a child of both bizContact
and bizLabel, but it cannot work because a bizObject can only have one
parent.
Finally, here is how I succeed updating the joining table:
First, I added bizContactlabel as a child of only bizContact. On save, I
first save the bizLabel. Then, I manually update negative keys for Label in
bizContactlabel. Finally, I save bizContact.
self.bizContact = app.biz.Contact(app.dbConnection)
self.bizLabel = app.biz.Label(app.dbConnection)
self.bizContactlabel = app.biz.Contactlabel(app.dbConnection)
self.bizContact.addChild(self.bizContactlabel)
# get list of existing labels
self.bizLabel.requery()
self.groups = self.bizLabel.getDataSet(("ID", "Name"))
self.groups = {x['Name']:x['ID'] for x in self.groups}
...
self.bizContact.setFieldVals(contact)
...
for g in groups:
if g in self.groups:
groupid = self.groups[g]
else:
self.bizLabel.new()
self.bizLabel.setFieldVal("Name", g)
groupid = self.bizLabel.getPK()
self.groups[g] = groupid # add new label to the list of existing
labels
self.bizContactlabel.new()
self.bizContactlabel.setFieldVal("Label", groupid)
...
self.bizLabel.saveAll()
assoc = {}
for gname, gid in self.groups.items():
if gid < 0:
self.bizLabel.seek(gname, "Name")
assoc[gid] = self.bizLabel.getPK() # Associate old (negatif) id
with newly generated id
def _myfun():
gid = self.bizContactlabel.getFieldVal("Label")
if gid < 0:
self.bizContactlabel.setFieldVal("Label", assoc[gid])
self.bizContactlabel.scanChangedRows(_myfun, allCursors=True,
includeNewUnchanged=True)
self.bizContact.saveAll()
Do you have any suggestions on a better way of doing it?
Charles.
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message:
http://leafe.com/archives/byMID/cajpgzxkorhf+5lhwlgtqbkt_+-rudgbxrn+gjcxxqv5rmxg...@mail.gmail.com