Assuming you meant: r.y.y.y.t It works because db.a.y is a self referencing field. Inserting into db.a doesn't return an int, but a Reference, which has a __getattr__ that returns the record it references. Any number of y's should work: r.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.t 't' is the virtual field which returns the length of the computed field, which in turn is 3*x. 'x' in this case is 'hello', so t is 15. You could also do: r.y.y.y.y.z to get the computed field which should return: hellohellohello
On Jul 22, 6:50 pm, "mr.freeze" <nat...@freezable.com> wrote: > It shouldn't. It should throw an error at the print statement because > 'a' is not defined. > > On Jul 22, 6:33 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > The following code uses: > > 1) a computed field > > 2) a self reference > > 3) a virtual field > > > >>> db.define_table('a',Field('x'),Field('y','reference > > >>> a'),Field('z',compute=lambda row: row['x']*3)) > > >>> class A: > > >>> def t(self): return len(self.a.z) > > >>> db.a.virtualfields.append(A()) > > >>> r=db.a.insert(x='hello') > > >>> r.update_record(x=r.x,y=r) > > >>> print a.y.y.y.y.t > > > 15 > > > Can you explain how it works?