mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-08-03 02:51:31 -04:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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: {
|
||||
|
||||
1
src/realmModels/types.d.ts
vendored
1
src/realmModels/types.d.ts
vendored
@@ -101,7 +101,6 @@ export interface RealmObservationFieldValuePojo extends RealmObject {
|
||||
uuid: string;
|
||||
id?: number;
|
||||
obsFieldId: number;
|
||||
projectId: number;
|
||||
value?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user