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

Saving Array of Pointers Saves the Whole Object of The Pointer #6174

Closed
bahaa-kallas opened this issue Nov 2, 2019 · 2 comments
Closed

Saving Array of Pointers Saves the Whole Object of The Pointer #6174

bahaa-kallas opened this issue Nov 2, 2019 · 2 comments

Comments

@bahaa-kallas
Copy link

bahaa-kallas commented Nov 2, 2019

Issue Description

When saving array of pointers each pointer saved along with the attributes of the referenced object
i noticed that there was already an issue open for this and then a PR applied and fix the issue
but it turns out that somehow its still exist
#6049

Steps to reproduce

this code used to save Parent Object which have list of PostCategory as Array of Pointers

 // Create Parent Object with  postCategories initialized as empty list and save it in the database
 val ceParent = Parent().apply {
      this.arName = "قسم هندسة الاتصالات"
      this.enName = "CE Department"
      this.postCategories = arrayListOf()
      this.channelName = "ce"
    }

    ceParent.save()

    // Create category object and link it to the previous Parent and save it in the database

    val ceGeneralAnnouncementCategory = PostCategory().apply {
      this.arName = ""
      this.enName = "General Announcement"
      this.channelName = "ceGenAnnounce"
      this.parent = ceParent
    }


    val ceGradesCategory = PostCategory().apply {
      this.arName = ""
      this.enName = "Exams Grades"
      this.channelName = "ceGrades"
      this.parent = ceParent
    }

    ceGeneralAnnouncementCategory.save()
    ceGradesCategory.save()


    // Get the Parent object and then update it with a list of the categories that you already saved
    ceParent.postCategories = arrayListOf(
        ceGeneralAnnouncementCategory,
        ceGradesCategory
    )

    ceParent.save()

Expected Results

saving array of pointers must be saved in this form :

[
  {
    "__type": "Pointer",
    "className": "PostCategory",
    "objectId": "OalNlXznGB"
  },
  {
    "__type": "Pointer",
    "className": "PostCategory",
    "objectId": "KEmcaV5R40"
  }
]

Actual Outcome

but when looking to the dashboard it looks like this

[
  {
    "parent": {
      "postCategories": [
        {
          "__type": "Pointer",
          "className": "PostCategory",
          "objectId": "shf1jCQhst"
        },
        {
          "parent": {
            "__type": "Pointer",
            "className": "Parent",
            "objectId": "sP0eiMLlbM"
          },
          "enName": "Exams Grades",
          "channelName": "itGrades",
          "arName": "",
          "createdAt": "2019-11-02T13:09:55.744Z",
          "updatedAt": "2019-11-02T13:09:55.744Z",
          "objectId": "tdijo6M8CD",
          "__type": "Object",
          "className": "PostCategory"
        }
      ],
      "enName": "IT Department",
      "channelName": "it",
      "arName": "قسم هندسة تقانة المعلومات",
      "createdAt": "2019-11-02T13:09:54.359Z",
      "updatedAt": "2019-11-02T13:10:10.204Z",
      "objectId": "sP0eiMLlbM",
      "__type": "Object",
      "className": "Parent"
    },
    "enName": "General Announcement",
    "channelName": "itGenAnnounce",
    "arName": "",
    "createdAt": "2019-11-02T13:09:55.160Z",
    "updatedAt": "2019-11-02T13:09:55.160Z",
    "objectId": "shf1jCQhst",
    "__type": "Object",
    "className": "PostCategory"
  },
  {
    "parent": {
      "postCategories": [
        {
          "parent": {
            "__type": "Pointer",
            "className": "Parent",
            "objectId": "sP0eiMLlbM"
          },
          "enName": "General Announcement",
          "channelName": "itGenAnnounce",
          "arName": "",
          "createdAt": "2019-11-02T13:09:55.160Z",
          "updatedAt": "2019-11-02T13:09:55.160Z",
          "objectId": "shf1jCQhst",
          "__type": "Object",
          "className": "PostCategory"
        },
        {
          "__type": "Pointer",
          "className": "PostCategory",
          "objectId": "tdijo6M8CD"
        }
      ],
      "enName": "IT Department",
      "channelName": "it",
      "arName": "قسم هندسة تقانة المعلومات",
      "createdAt": "2019-11-02T13:09:54.359Z",
      "updatedAt": "2019-11-02T13:10:10.204Z",
      "objectId": "sP0eiMLlbM",
      "__type": "Object",
      "className": "Parent"
    },
    "enName": "Exams Grades",
    "channelName": "itGrades",
    "arName": "",
    "createdAt": "2019-11-02T13:09:55.744Z",
    "updatedAt": "2019-11-02T13:09:55.744Z",
    "objectId": "tdijo6M8CD",
    "__type": "Object",
    "className": "PostCategory"
  }
]

Environment Setup

  • Server
    • parse-server version : 3.9.0
    • Parse Hosted by: Back4app

Note

this behaviour doesn't affect querying the Parent Object (Who has the array of pointers field)
i still able to get the array of pointers objects with include

val query = ParseQuery.getQuery(Parent::class.java)
    query.whereEqualTo("objectId","uYn8FF1Qcd")
    query.include(Parent::postCategories.name)

    val result = query.first.postCategories

    result?.forEach{
      Log.d("PARENT : ","${it.channelName}")
    }

UPDATE

maybe its problem with parse dashboard. i cleared all the records in the Parent Class and made the insertion step again and the result was as expected. but when i have made another insertion the object who saved correctly and the newly inserted object has the Array of pointers field changed to the whole object saved along with each pointer

@dplewis
Copy link
Member

dplewis commented Nov 4, 2019

@bahaa-kallas this is a catch 22.

This discussion and change parse-community/parse-dashboard#1223

If this breaks anything for you let us know.

@bahaa-kallas
Copy link
Author

Final Update :
everything is working fine, you can query the array of pointers always even if it shown in the dashboard as whole object saved or only pointer related fields
the problem is with parse dashboard and the most interesting fact that when you insert your data first it will be shown as whole object is saved but if you checked it afterward (closed the browser tab and reopen) you will see the normal behaviour appears
i will close this because the (buggy) behaviour seems to be not causing any problems (as i already said you can always query the data and get correct results)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants