I currently have two schemas on my app:
Playlist
export default class Playlist extends Realm.Object {
static schema = {
name: 'Playlist',
primaryKey: 'id',
properties: {
id: {type: 'int', indexed: true},
title: 'string',
songs: 'Song[]',
author: 'string',
isDownloaded: {type: 'bool', default: false},
},
}
}
Song
export default class Song extends Realm.Object {
static schema = {
name: 'Song',
primaryKey: 'id',
properties: {
id: {type: 'int', indexed: true},
title: 'string',
url: 'string',
artwork: 'string',
artist: 'string',
stringId: 'string',
slowed: 'bool',
},
}
}
Display a Playlist's songs
Songs being displayed correctly
Song with the same id from the current Playlist is returned as Circular Object, that returns the playlist itself when accessed, after calling toJSON()

When I console log this object before calling toJSON(), the Song is shown correctly
When I console log this object after I called this.realm(Playlist).toJSON(), it returns the playlist itself
// '8' is the index of this Circular Object
console.log(realm.objects(Playlist)[0].songs[8]) // Works fine
console.log(realm.objects(Playlist).toJSON()[0].songs[8]) // Returns the `Playlist` itself, instead of the `Song`
Create a Playlist containing an id equals to one of it's Songs.
Call toJSON()
const playlist = realm.objects(Playlist).toJSON()[0]
console.log(playlist)
Error now located, expect a fix in the next release.
@gustavo-dev just a quick note — you don't have to write indexed to id property, since it's a primary key and indexed by default :)
Most helpful comment
@gustavo-dev just a quick note — you don't have to write
indexedtoidproperty, since it's a primary key and indexed by default :)