I am currently navigating the complexities of sequelize and express, facing challenges with database associations and data retrieval. My project involves a boarders-boards (focused on surfboards and riders) database with three main models: Boards, Riders, and Makers. - Each maker can have multiple boards, and each board belongs to only one maker, which is a straightforward association. - A rider can have multiple boards, and a board can belong to multiple riders.
During database population, I encountered an OID error that sporadically appears but then disappears.
Now, in my api/riders route, I am struggling to retrieve a populated array consisting of all rider objects using the "findAll()" method. Unfortunately, it returns an empty array. Is this issue related to my database setup, the associations, or the API route? How can I overcome this challenge and successfully retrieve the desired information?
This is my api/riders route:
const router = require('express').Router();
const asyncHandler = require('express-async-handler');
const { Rider } = require('../database/index');
// Route handling code here
This is the index for my db models:
"use strict";
const db = require("./db");
const Board = require("./board");
const Rider = require("./rider");
const Maker = require("./maker");
// Associations defined here
Maker.hasMany(Board);
Board.belongsTo(Maker);
Board.belongsToMany(Rider,{through: 'RiderBoards'});
Rider.belongsToMany(Board,{through:'RiderBoards'});
module.exports = {
db,
Board,
Rider,
Maker
};
This is the index on the server side:
const express = require("express");
// Additional required modules
// Server setup and middleware configuration
Your assistance and guidance on overcoming this issue would be greatly appreciated!