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

Copying same object multiple time while writing JSON that contains multiple nested objects #3254

Closed
iamprahlad opened this issue Sep 23, 2020 · 4 comments · Fixed by #3257
Closed
Assignees

Comments

@iamprahlad
Copy link

iamprahlad commented Sep 23, 2020

Goals

Writing JSON that contains multiple nested objects

Expected Results

{
    id: '12324',
    age: 22,
    name: 'Pankaj',
    phones: [{ model: 'Redmi 5A', price: 60000 }, { model: 'Nokia Lumia X2', price: 5000 }, { model: 'Nokia A1', price: 8000 }],
    car: { model: 'i20', price: 500000, launchDate: new Date(1600028986548) },
    address: {
        addressLocality: "Khatima",
        addressRegion: "Uk",
        postalCode: "262308",
        streetAddress: "Hill View Colony "
    }
}

Actual Results

{
    address: { model: "Redmi 5A", price: 60000, $refId: "RealmObject{0000-0000}" },
    age: 22,
    car: { model: "Redmi 5A", price: 60000, $refId: "RealmObject{0000-0000}" },
    id: "12324",
    name: "Pankaj",
    phones: [
        { model: "Redmi 5A", price: 60000, $refId: "RealmObject{0000-0000}" },
        { model: "Nokia Lumia X2", price: 5000, $refId: "RealmObject{0000-0001}" },
        { model: "Nokia A1", price: 8000, $refId: "RealmObject{0000-0002}" }
    ]
}

Steps to Reproduce

Code Sample

const PersonSchema = {
    name: 'Person',
    primaryKey: 'id',
    properties: {
        id: 'string',
        age: 'int',
        name: 'string',
        phones: 'Phone[]',
        car: 'Car',
        address: 'Address'
    }
}

const PhoneSchema = {
    name: 'Phone',
    properties: {
        model: 'string',
        price: 'int'
    }
}

const CarSchema = {
    name: 'Car',
    properties: {
        model: 'string',
        price: 'int',
        launchDate: 'date',
    }
}

const addressSchema = {
    name: 'Address',
    properties: {
        streetAddress: 'string?',
        postalCode: 'string?',
        addressRegion: 'string?',
        addressLocality: 'string?'
    }
}

const dummyPersonData = {
    id: '12324',
    age: 22,
    name: 'Pankaj',
    phones: [{ model: 'Redmi 5A', price: 60000 }, { model: 'Nokia Lumia X2', price: 5000 }, { model: 'Nokia A1', price: 8000 }],
    car: { model: 'i20', price: 500000, launchDate: new Date(1600028986548) },
    address: {
        addressLocality: "Khatima",
        addressRegion: "Uk",
        postalCode: "262308",
        streetAddress: "Hill View Colony "
    }
}


const readTestData = () => {
    Realm.open({ schema: [addressSchema, PersonSchema, CarSchema, PhoneSchema] }).then(realm => {
        try {
            const result = realm.objects('Person')
            console.log('result', result.toJSON())
        } catch (e) {
            console.log('unable to read', e)
        }
        return realm.close();
    }).catch(error => {
        console.log('error ', error)
    })

}

const writeTestData = () => {
    Realm.open({ schema: [addressSchema, PersonSchema, CarSchema, PhoneSchema] }).then(realm => {
        try {
            realm.write(() => {
                realm.create('Person', dummyPersonData)
                console.log('done')
            })
        } catch (e) {
            console.log('unable to write', e)
        }
        return realm.close();
    }).catch(error => {
        console.log('error ', error)
    })
}

Version of Realm and Tooling

  • Realm JS SDK Version: ?
  • Node or React Native: ?
  • Client OS & Version: ?
  • Which debugger for React Native: ?/None
@iamprahlad iamprahlad changed the title Writing JSON that contains multiple nested objects Copying same object multiple time while writing JSON that contains multiple nested objects Sep 23, 2020
@steffenagger
Copy link
Contributor

Hello @iamprahlad, thanks for reporting this.
(I took the liberty to wrap the code-examples in code-blocks for readability, hope that's ok)

The cause has been found, and a fix will be included in the next release (both v6 & v10-beta).
Just curious, what version of Realm are you currently using?

@iamprahlad
Copy link
Author

Hi @steffenagger, thanks for help.
I'm using realm version 6.1.1.

@alexandrethsilva
Copy link

@steffenagger do you know when this fix will be released? I'm currently on 6.1.2 and that release was made 13 days ago. It's a blocking issue for me currently. 🙈

@steffenagger
Copy link
Contributor

@alexandrethsilva we're awaiting some important fixes, but the upcoming release should be out one of the following days.

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

Successfully merging a pull request may close this issue.

3 participants