realm-js: RealmObject cannot be called as a function - Only Android
Goals
When I try to use objectForPrimaryKey or objects it’s working as expected in Both iOS and Android. like as below:
// Working fine
const categoryData = realmRef.objects<CategorySchema>(CategorySchema).filtered(filterQuery).sorted('name');
// Create is not working in Android working fine in iOS
function saveCategory(values: ICategorySchema) {
try {
realmRef.write(() => {
realmRef.create<CategorySchema>(CategorySchema, values, Realm.UpdateMode.Modified);
});
setIsCategoryFormModalVisible(false);
} catch ({message}) {
// eslint-disable-next-line no-console
console.error(message);
}
}
ERROR RealmObject cannot be called as a function
Expected Results
No issues while saving in iOS. Should as fine in Android like iOS.
Actual Results
In Android it’s throwing {{ ERROR RealmObject cannot be called as a function}} on Create.
Steps to Reproduce
Code Sample
import {UUIDType} from '@src/types';
import Realm from 'realm';
export interface ICategorySchema {
_id: UUIDType;
name: string;
notes?: string;
categoryType: number; // 0 - Income; 1 - Expenses
}
export class CategorySchema extends Realm.Object implements ICategorySchema {
public _id: UUIDType;
public name: string;
public notes?: string;
public categoryType: number;
public static schema: Realm.ObjectSchema = {
name : 'Category',
primaryKey : '_id',
properties : {
_id : 'uuid',
name : 'string',
categoryType : 'int',
notes : 'string?'
}
};
}
import Realm from 'realm';
import {
CategorySchema,
} from './schemas';
// prettier-ignore
const realmRef = new Realm(
{
schema : [
CategorySchema,
],
deleteRealmIfMigrationNeeded : __DEV__
}
);
export default realmRef;
Version of Realm and Tooling
- Realm JS SDK Version: “realm”: “^10.6.1”
- Node or React Native: “react-native”: “0.64.2”,
- Client OS & Version: macOS Big Sur Version 11.5
- Which debugger for React Native: None
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 28 (13 by maintainers)
Still facing the same issue, with @realm/react and the hooks useRealm, useQuery.
@saravanakumargn Ah, are you calling
newon your Realm Model class? We do have some known issues involved with making a class extending “Realm.Object”. Can you try declaring your class without the extension and doing creates like so:realm.create<ObjectClass>('ObjectClass', value)This may be a workaround until we fix Class Based Models.Thank you so much. You saved my life @takameyer. It works now with
"realm": "11.0.0-rc.2"Hi @saravanakumargn. Thanks for reporting this. We’ll look into the issue. Is this a new issue in Realm JS 10.6.1, or have you seen it with previous versions?