edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Document that checking a bool property in querybuilder will always result in `true`

Open raddevon opened this issue 1 year ago • 0 comments

If you check the boolean value of a property in JavaScript (without using e.op or similar), the result will always be truthy since that is not the value in the data but an object that is part of the query builder which itself is always truthy.

// 🚫
const products = await e.select(e.Product, (product) => ({
  token_amount: product.show_token_amount ? true: false
})).run(client);
// ✅
const products = await e.select(e.Product, (product) => ({
    token_amount: e.op(product.token_amount, "if", product.show_token_amount, "else", e.int32(0)),
}).run(client);

Context: https://discord.com/channels/841451783728529451/849374705210490900/1080892880526262283

raddevon avatar Sep 20 '23 14:09 raddevon