So, as suggested in This post I made the following changes :
//models/artist-medias
const ArtistsMedias = sequelize.define('artistsMediasUrl', {...}
and
//models/artists
Artists.associate = (models) => {
Artists.hasMany(models.artistsMediasUrl, {
foreignKey: {
name: 'artistIdKey',
field: 'artist_id',
},
as: 'artistsMedias',
});
And it’s now working!
The issue seemed to be that “media” was pluralized into “medium” and the resolver did not find any matching model…
Edit :
After watching the different requests made :
- When querying the related data, we call https://[ForestUrl]/artists/[ArtistId]/relationships/artistsMedias (using the alias we gave in the artist model, seems logic)
- When querying all the media table, we call https:/[forestUrl]/forest/artistsMediasUrl/ (seems legit as well, since I changed the model name for sequelize)
The question I am asking myself now is how it is able to get the artistMedias through this route, since I made no changes to the routes folder?
My routes/artist-media still looks like
const express = require('express');
const { PermissionMiddlewareCreator } = require('forest-express-sequelize');
const { artistsMedias } = require('../models');
const router = express.Router();
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('artistsMedias');
// Create a Artists Media
router.post('/artistsMedias', permissionMiddlewareCreator.create(), (request, response, next) => {
next();
});
// And so on...
Since this is working and all i am just wondering in case We’ll have to add some modifications to the route resolvers later, I don’t quite understand
Should I get rid of this file and create an artist-medias-url file in the route folder?