From 05b610cdfd36c076a4407fc0dc79fc526bd763a6 Mon Sep 17 00:00:00 2001 From: Johannes Klein <17345891+jtklein@users.noreply.github.com> Date: Wed, 24 Jun 2026 12:39:58 +0200 Subject: [PATCH] Remove projectId from OFV realm This was a mistake. I thought we'd need to tie an OFV to a specific PO/project, but they are global pieces of evidence at the time of making an observation. --- src/realmModels/ObservationFieldValue.ts | 8 ++------ src/realmModels/index.ts | 2 +- src/realmModels/types.d.ts | 1 - .../unit/models/ObservationFieldValue.test.js | 19 +++++++++---------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/realmModels/ObservationFieldValue.ts b/src/realmModels/ObservationFieldValue.ts index 9048cd11d..ebb95730a 100644 --- a/src/realmModels/ObservationFieldValue.ts +++ b/src/realmModels/ObservationFieldValue.ts @@ -19,7 +19,6 @@ class ObservationFieldValue extends Realm.Object { } static new( - projectId: number, obsFieldId: number, value?: string, ) { @@ -27,19 +26,17 @@ class ObservationFieldValue extends Realm.Object { _created_at: new Date( ), _updated_at: new Date( ), uuid: uuid.v4( ).toLowerCase( ), - projectId, obsFieldId, value, }; } - static findForProject( + static findForObsField( observation: RealmObservation, - projectId: number, obsFieldId: number, ): RealmObservationFieldValue | undefined { return observation.observationFieldValues.find( - ofv => ofv.projectId === projectId && ofv.obsFieldId === obsFieldId, + ofv => ofv.obsFieldId === obsFieldId, ); } @@ -67,7 +64,6 @@ class ObservationFieldValue extends Realm.Object { uuid: "string", id: "int?", obsFieldId: "int", - projectId: "int", value: "string?", // this creates an inverse relationship so OFVs // automatically keep track of which Observation they are assigned to diff --git a/src/realmModels/index.ts b/src/realmModels/index.ts index 1251f7dcc..fa4decbb3 100644 --- a/src/realmModels/index.ts +++ b/src/realmModels/index.ts @@ -43,7 +43,7 @@ export default { User, Vote, ], - schemaVersion: 69, + schemaVersion: 70, path: `${DocumentDirectoryPath}/db.realm`, // https://github.com/realm/realm-js/pull/6076 embedded constraints migrationOptions: { diff --git a/src/realmModels/types.d.ts b/src/realmModels/types.d.ts index 0b215f906..9a9fbd860 100644 --- a/src/realmModels/types.d.ts +++ b/src/realmModels/types.d.ts @@ -101,7 +101,6 @@ export interface RealmObservationFieldValuePojo extends RealmObject { uuid: string; id?: number; obsFieldId: number; - projectId: number; value?: string; } diff --git a/tests/unit/models/ObservationFieldValue.test.js b/tests/unit/models/ObservationFieldValue.test.js index c648d38a0..9a3ccbfee 100644 --- a/tests/unit/models/ObservationFieldValue.test.js +++ b/tests/unit/models/ObservationFieldValue.test.js @@ -5,9 +5,8 @@ import * as uuid from "uuid"; describe( "ObservationFieldValue", () => { describe( "new", () => { it( "should construct an OFV", () => { - const ofv = ObservationFieldValue.new( 7, 99, "male" ); + const ofv = ObservationFieldValue.new( 99, "male" ); expect( ofv.uuid ).toBe( ofv.uuid.toLowerCase() ); - expect( ofv.projectId ).toBe( 7 ); expect( ofv.obsFieldId ).toBe( 99 ); expect( ofv.value ).toBe( "male" ); expect( ofv._created_at ).toBeInstanceOf( Date ); @@ -15,8 +14,8 @@ describe( "ObservationFieldValue", () => { } ); } ); - describe( "findForProject", () => { - it( "should find an OFV scoped by projectId and obsFieldId", () => { + describe( "findForObsField", () => { + it( "should find an OFV by obsFieldId", () => { const obsUuid = uuid.v4(); safeRealmWrite( global.realm, @@ -24,18 +23,18 @@ describe( "ObservationFieldValue", () => { global.realm.create( "Observation", { uuid: obsUuid, observationFieldValues: [ - ObservationFieldValue.new( 1, 10, "a" ), - ObservationFieldValue.new( 2, 10, "b" ), + ObservationFieldValue.new( 10, "a" ), + ObservationFieldValue.new( 20, "b" ), ], } ); }, - "create Observation with scoped OFVs", + "create Observation with OFVs", ); const obs = global.realm.objectForPrimaryKey( "Observation", obsUuid ); - expect( ObservationFieldValue.findForProject( obs, 2, 10 )?.value ).toBe( "b" ); - expect( ObservationFieldValue.findForProject( obs, 1, 10 )?.value ).toBe( "a" ); - expect( ObservationFieldValue.findForProject( obs, 3, 10 ) ).toBeUndefined(); + expect( ObservationFieldValue.findForObsField( obs, 20 )?.value ).toBe( "b" ); + expect( ObservationFieldValue.findForObsField( obs, 10 )?.value ).toBe( "a" ); + expect( ObservationFieldValue.findForObsField( obs, 99 ) ).toBeUndefined(); } ); } ); } );