hackforla / hackforla/VRMS

Fix missing Mongoose ref options on schema fields

Open
#2,165 0 comments 0 reactions 0 assignees View on GitHub
complexity: small feature: Database housekeeping role: Back End role: Database size: 0.25pt
Dominant language
JavaScript
Stars
61
Forks
101
PR merge metrics
No merged PRs in 30d

Description

## Problem

9 fields across 6 model files are defined as plain `String` or `Number` types without a `ref` option, which breaks `.populate()` calls at runtime.

### Affected Files

| File | Field(s) | Current Type | Should Reference |
|------|----------|-------------|-----------------|
| `projectTeamMember.model.js` | `usersId`, `projectId` | `String` | `User`, `Project` |
| `checkIn.model.js` | `eventId`, `userId` | `String` | `RecurringEvent`, `User` |
| `event.model.js` | `projectId` | `String` | `Project` |
| `recurringEvent.model.js` | `projectId` | `String` | `Project` |
| `user.model.js` | `currentRole` | `Number` | N/A (convert to `ObjectId` ref to future Role model, or keep as enum — needs decision) |
| `project.model.js` | `projectStatus`, `googleDriveId` | `String` | N/A (convert to proper schema options) |

## Impact

- `.populate()` silently returns `null` for these fields because Mongoose cannot resolve the reference
- This is a **prerequisite** for the manager toggle feature (#2149)
- Relates to #2155

## Fix

Convert plain String fields to `{ type: Schema.Types.ObjectId, ref: "ModelName" }` where an association exists. For fields that are true scalars (enums, IDs from external systems), ensure proper schema options are applied.

## Scope

Schema-only change — no API or UI modifications required.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.