question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'objectType' must be of type : string

See original GitHub issue

Hi 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:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
wilomgfxcommented, Mar 9, 2017

ok its fixed, my problem was using the static property schema on my User object and passing the User constructor directly. Instead of doing :


const realm = new Realm({schema: [User, City]})

I have to do :


const realm = new Realm({schema: [User.schema, City.schema]})

Thanks everyone !

2reactions
noisypigeoncommented, Feb 27, 2017

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found