[PEAK] model unit tests and a non-association QueryLink

Phillip J. Eby pje at telecommunity.com
Tue Nov 9 23:19:28 EST 2004


At 10:37 PM 11/9/04 -0500, R. David Murray wrote:
>On Tue, 9 Nov 2004, Phillip J. Eby wrote:
> > That's correct.  A QueryLink is an implementation thing.  Remember that
> > '_load()' and '_new()' deal with the object's implementation; they should
> > not be using the client API.  Setting an attribute is client API.
>
>Hmm.  That makes sense.  That presumably means I've been doing my
>generated-id handling wrong, and need to rewrite things so that
>I'm obtaining the id to store in the database record using oidFor
>instead of also storing it in an attribute.
>
> > >Hmm.  Maybe my storage model is flawed?  I mean, how can a QueryLink
> > >know that it needs to invaliate its value when the database rows
> > >it is based on change, when it isn't being updated by an association?
> >
> > Correct.
>
>Good.  Glad to know PEAK isn't truly magical (*grin*).
>
> > So there should be a relationship from Account.transactions <->
> > Transaction.billedaccount; each should have a 'referencedEnd' pointing to
> > the other.
>
>Yes, there is.
>
> > At that point, 'unbilledtransactions' could then be a derived attribute.
>
>Ah, that's the missing piece.  The first time I read over DerivedAttribute
>I didn't understand how it worked.  With this additional hint I think
>I understand it.
>
>Is there a better way to implement this than just filtering the
>transactions list every time the attribute is accessed?

Yes, use a QueryLink referencing a QueryDM.  One way to do this "cheaply" 
is to make your existing transaction-list QueryDM take a key that's an 
'(id,unbilled_only)' tuple, that it then uses when querying the SQL 
backend.  Then, the account state ends up with two query links, one to the 
full transaction list, the other to the unbilled ones.  Only the ones you 
actually use will be loaded.

Also, keep in mind that QueryDM's need to use preloadState() on the DM 
whose objects they're loading, so that you don't have to go back and load 
those objects' states again.




More information about the PEAK mailing list