Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to-many Relationship returning Circular object when ids are them same #3331

Closed
tavindev opened this issue Oct 10, 2020 · 2 comments
Closed
Assignees

Comments

@tavindev
Copy link

tavindev commented Oct 10, 2020

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',
        },
    }
}

Goals

Display a Playlist's songs

Expected Results

Songs being displayed correctly

Actual Results

Song with the same id from the current Playlist is returned as Circular Object, that returns the playlist itself when accessed, after calling toJSON()

image

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`

Steps to Reproduce

Create a Playlist containing an id equals to one of it's Songs.
Call toJSON()

Code Sample

const playlist = realm.objects(Playlist).toJSON()[0]
console.log(playlist)

Version of Realm and Tooling

  • Realm JS SDK Version: 6.1.3
  • Node or React Native: 4.12.0
  • Client OS & Version: Win 10
  • Which debugger for React Native: None
@RealmBot RealmBot changed the title to-many Relationship returning Circular object to-many Relationship returning Circular object Oct 10, 2020
@tavindev tavindev changed the title to-many Relationship returning Circular object to-many Relationship returning Circular object after calling toJSON() Oct 10, 2020
@tavindev tavindev changed the title to-many Relationship returning Circular object after calling toJSON() to-many Relationship returning Circular object when ids are them same Oct 10, 2020
@steffenagger steffenagger self-assigned this Oct 15, 2020
@steffenagger
Copy link
Contributor

Error now located, expect a fix in the next release.

This was referenced Oct 21, 2020
@isnifer
Copy link

isnifer commented Oct 21, 2020

@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 :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants