'objectType' must be of type : string
See original GitHub issueHi im getting this error as soon as i call one on my methods inside realm.ts which is below
My models with realm schemas (models.ts)
import { ICity, IUser } from './interfaces'
import Realm , { ObjectSchema, PropertyType } from 'realm'
export class City implements ICity {
// static get () { return realm.objects(City.schema.name) }
static schema : ObjectSchema = {
name: 'City',
primaryKey : 'id',
properties : {
id : {type : 'string'},
cityName : {type : 'string'},
localImg : {type : 'string', optional: true},
sourceLogo : {type : 'string', optional: true},
cityCode : {type : 'list'},
}
}
constructor(cityName?: string, cityCode?: string, sourceLogo?: string, localImg?: string) {
this.cityName = cityName
this.cityCode = cityCode
this.sourceLogo = sourceLogo
this.localImg = localImg
}
public cityName: string;
public localImg: string;
public sourceLogo: string;
public cityCode: string;
}
export class User implements IUser {
//TODO: hash users pw
static schema : ObjectSchema = {
name: 'User',
primaryKey : 'id',
properties : {
id : {type : 'string'},
fullName : {type : 'string'},
user : {type : 'string'},
pw : {type : 'string'},
cities : {type : 'list', objectType: 'City'},
}
}
public fullName: string;
public user: string;
public pw: string;
public cities: Array<ICity>;
constructor(fullName?: string, user?: string, pw?: string, cities?: Array<ICity>) {
this.fullName = fullName
this.user = user
this.pw = pw
this.cities = cities
}
}
Where realm happens (realm.ts)
import Realm from 'realm'
import { ListView } from 'realm/react-native'
import uuid from 'uuid'
import { User, City } from '../types/models';
//export const userItemDS = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.id !== r2.id})
export const getUsers = () => {
const users = realm.objects('User').sorted('id', true)
console.log(users);
return users
}
export const getUser = (id : string) => {
const user = realm.objectForPrimaryKey(User, id)
console.log(user);
return user
}
export const saveUser = ({fullName, user, pw} : User) => {
realm.write(() => {
realm.create(User.schema.name, {
id: uuid.v1(),
fullName,
user,
pw
})
})
}
const realm = new Realm({schema: [User, City]})
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Realm DB React native Schema - type must be of type 'string ...
Whenever I try to add the MessagesSchema to the Schema array, it gives me a promise rejection, and the data from the ChatlistChema...
Read more >Documentation - Advanced Types - TypeScript
This page lists some of the more advanced ways in which you can model types, it works in tandem with the Utility Types...
Read more >JS exception - undefined type for schema object - MongoDB
Unhandled JS Exception: Error: type must be of type 'string', got (undefined) which tells me it's not recognizing the schema object.
Read more >Object type | Opis JSON Schema
arrays of strings representing property names, then the object must contain all property names. ... Starting with draft 2019-09 you should use dependentRequired ......
Read more >GraphQL specification
A GraphQL Document describes a complete file or request string operated on by ... The query root operation type must be provided and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ok its fixed, my problem was using the static property schema on my User object and passing the User constructor directly. Instead of doing :
I have to do :
Thanks everyone !
Hi @wilomgfx. Thanks for reaching out. My apologies for the delay in someone getting back to you. The Javascript team is rather small and one of our JS engineers is currently on vacation. We’ll try to get back to you as soon as we can!