Shapes
Sometimes it is not enough to fetch the data as is, but
it is necessary to add something extra to it. This can
be done by adding a computed field to the shape. Let's
fetch all the accounts and add the username
length as
well as the length of their watchlist
to the results:
We can even incorporate a comparison to the average username
length in our computed field. There are several ways to do this,
but in this example we'll use the detached
keyword.
Using detached
denotes that the Account
that we're
referring to in the subquery is the original unmodified set
in the database rather than the object for which we're computing
the value of above_avg
:
On the next page, we'll learn to use a with
block to do the
same query in a more readable way.