Skip to content

Instantly share code, notes, and snippets.

@icnahom
Last active March 23, 2022 16:30
Show Gist options
  • Save icnahom/8b31d5bca0ca1aa39305d1bff646adca to your computer and use it in GitHub Desktop.
Save icnahom/8b31d5bca0ca1aa39305d1bff646adca to your computer and use it in GitHub Desktop.
getting docs by a foreign key
products = (
await r.table("saved")
.order_by(r.desc("saved_at"))
.filter(r.row["user_id"] == user_id)
.eq_join("product_id", r.table("products"))
.map(lambda doc: doc["right"].merge(make_merge_expr))
.limit(25)
.run(self.conn)
)
products = (
await r.table("saved")
.order_by(r.desc("saved_at"))
.filter(r.row["user_id"] == user_id)
.eq_join("product_id", r.table("products"))["right"]
.merge(make_merge_expr)
.limit(25)
.run(self.conn)
)
# if concat_map use get_all
products = (
await r.table("saved")
.order_by(r.desc("saved_at"))
.filter(r.row["user_id"] == user_id)
.map(lambda save: r.table("products").get(save["product_id"]))
.merge(make_merge_expr)
.limit(25)
.run(self.conn)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment