Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save david-mart/a223c8ae1abdc871a3674d1003f1dc22 to your computer and use it in GitHub Desktop.
Save david-mart/a223c8ae1abdc871a3674d1003f1dc22 to your computer and use it in GitHub Desktop.
const product = await UsersDb.models.order.findOne({
where: { id: 1 },
include: [
{
model: ProductsDb.models.product,
on: {
// this is where magic happens
order_id: Sequelize.literal("`order`.`id` = `products`.`products`.`order_id`")
}
}
]
});
console.log(product);
// output
{ id: 1,
user_id: 1,
order_date: 2019-05-10T07:00:00.000Z,
products:
[ { id: 1, order_id: 1, name: 'oathkeeper' },
{ id: 2, order_id: 1, name: 'longclaw' },
{ id: 3, order_id: 1, name: 'needle' } ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment