Created
June 11, 2019 21:18
-
-
Save david-mart/a223c8ae1abdc871a3674d1003f1dc22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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