Allow specifying javascript types for field types.
Corrected bug in querying system.

Bug caused the referencing document, rather than the refered
document to be loaded when executing a query.