Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User{id, name, phone, email}
- Cars{id, name, manufacturer}
- UserCars{id, car_id, user_id, role}
- User have many cars(through UserCars)
- Cars have many users(through UserCars)
- router.get('/', async (req, res) => {
- try {
- let car = await Car.findOne({
- where: {
- id: req.car_id
- }});
- let users = await car.getUsers({joinTableAttributes: ['role']})
- res.send(users)
- } catch (e) {
- console.log(e)
- res.status(400).send(e)
- }
- })
- [
- {
- "id": 1,
- "name": "test",
- "email": null,
- "phone": null,
- "createdAt": "2019-07-09T09:38:11.859Z",
- "updatedAt": "2019-07-12T04:34:20.922Z",
- "User_car": {
- "role": "driver"
- }
- }
- ]
- [
- {
- "id": 1,
- "name": "test",
- "email": null,
- "phone": null,
- "role": 'driver'
- "createdAt": "2019-07-09T09:38:11.859Z",
- "updatedAt": "2019-07-12T04:34:20.922Z"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement