I’m using Sequelize with a postgresql database, which natively supports arrays. So I am trying to load a single artifact by pk, and all artists where the artistID is contained within the artist model at artist.artifactID, which is an array of integers.
If I don’t try to eagerly load the artists and just load them all it returns the proper data. I’m sure I’m not eagerly loading the data correctly, but I haven’t had any luck finding info on this since arrays in Sequelize are specific to postgresql databases.
Sorry if the answer is obvious, I’m new and still learning.
API
const router = require('express').Router();
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const { Artist, Post, Artifact } = require('../db');
//GET /api/ all artifacts
router.get('/', async(req, res, next) => {
try {
const artifactList = await Artifact.findAll();
res.send(artifactList)
} catch (e) {
next(e);
}
});
router.get('/:id', async(req, res, next) => {
try {
const artifact = await Artifact.findByPk(req.params.id);
const artists = await Artist.findAll({
where: {
[Op.in]: parseInt(req.params.id)
}
});
res.send({artifact, artists});
} catch (e) {
next(e);
}
})
module.exports = router;
ERROR
GET https://octopus-house.herokuapp.com/api/artifacts/1 500 (Internal Server Error)