On Aug 1, 2009, at 3:12 PM, Miguel Lopes wrote:
> Let me explain better:
> if I do - at a bizobj method:
>
> ### Code
> self.startTransaction()
>
> if someCondition:
> anotherBizobj =
> self.Application.biz.AnotherOtherBizobj(self.Connection)
So you are creating a brand-new instance of a bizobj here? You're not
using an existing bizobj that already has data in it?
> anotherBizobj.save(startTransaction=False)
Again, if you just created the bizobj, how can it have any modified
records to save?
> anotherPk = another.Record.pk
Only use this if you know that the PK field for that bizobj is named
'pk'. Usually, though, it's best not to assume too much about another
bizobj, and stick to the public getPK() method.
> self.save(startTransaction=False)
You don't need the parameter here, although it doesn't hurt. Bizobjs
can tell if they are already inside a transaction.
> for rec in someDSGotAsArgument:
> if rec == whatever:
> rec['field'] = anotherPk
> else:
> rec['field'] = self.Record.pk
I'll have to assume that this is correct behavior. Usually, though,
if I'm storing one table's PK in another table, that means that they
are related, and I would rely on normal parent-child behaviors to
manage these keys.
> ...
>
> if not self.commitTransaction():
> self.rollbackTransaction()
Generally you want to catch errors in your saves, and when an error
is encountered, rollback everything. Only if no errors occur do you
call commitTransaction.
>
> ### End code
>
> Is this the proper way to access pks of records that might be created?
Again, this non-relationship between tables is kind of confusing to
me, but I'll assume that you understand why you have it set up this way.
-- Ed Leafe
_______________________________________________
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/[email protected]