Skip to content

Commit

Permalink
Transform colKey to string before storing and looking it up
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Apr 3, 2023
1 parent 97e8dba commit e42d41c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/realm/src/PropertyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export class PropertyMap {
private objectSchemaName: string | null = null;
private initialized = false;
private mapping: Record<string, PropertyHelpers | undefined> = {};
private nameByColumnKey: Map<binding.ColKey, string> = new Map();
/**
* Note: Cannot key by the binding.ColKey directly, as this is `Long` on JSC (which does not compare equal)
*/
private nameByColumnKeyString: Map<string, string> = new Map();
private _names: string[] = [];

public initialize(objectSchema: BindingObjectSchema, defaults: Record<string, unknown>, options: HelperOptions) {
Expand All @@ -51,7 +54,7 @@ export class PropertyMap {
return [propertyName, helpers];
}),
);
this.nameByColumnKey = new Map(properties.map((p) => [p.columnKey, p.publicName || p.name]));
this.nameByColumnKeyString = new Map(properties.map((p) => [p.columnKey.toString(), p.publicName || p.name]));
this._names = properties.map((p) => p.publicName || p.name);
this.initialized = true;
}
Expand All @@ -70,7 +73,7 @@ export class PropertyMap {

public getName = <T>(columnKey: binding.ColKey): keyof T => {
if (this.initialized) {
return this.nameByColumnKey.get(columnKey) as keyof T;
return this.nameByColumnKeyString.get(columnKey.toString()) as keyof T;
} else {
throw new UninitializedPropertyMapError();
}
Expand Down

0 comments on commit e42d41c

Please sign in to comment.