0

I'm using Parse sdk for android.

In offline mode, I created some parse objects and pinned them using

  ...
  ParseObject.pinAll(cartItems)
  orderObject.pin()       //orderObject.objectId() returns null!
  ...

Later when i query cartItems in localDatastore i use

    ...
    query.whereEqualTo("order", orderObject);
    query.fromLocalDatastore().ignoreACLs();
    ...

but the query gives no result,probably because objectId of orderObject is null.

Is there any way to execute this query successfully?

If parse is incapable to do this should i go for Room database to store the data offline or is there any better alternative?

Any help is appreciated.

EDIT:

There are two subclasses

Order extends ParseObject 
OrderIte extends ParseObject

I create some OrderItem-s and one order. I put Order pointer in OrderItem-s and pin them all.

Later when i query OrderItem class in local datastore I want to retrieve OrdeItem-s for a perticular order. So in the OrderItem query i set

query.equaTo("order",myOrder.getObjectId())

But since the device is offline the whole time myOrder.getObjectId() returns null and the query fails to find the orderItems for myOrder

Expected query -> Select all from OrderItem where order = myOrder.getObjectId()
Actual query parse makes -> Select all from OrderItem where order = null

null as the object is stored offline in localdatastore.

ParseObject pinInBackground returning null objectId

This makes basic queries fail and makes the LocalDatastore less useful.

Manuel
  • 14,274
  • 6
  • 57
  • 130
Omkar T
  • 755
  • 8
  • 19
  • What is the class that you are trying to query? How does it relate to order? Have you also pinned the objects of this class? – Davi Macêdo Jan 17 '20 at 09:00
  • Question updated.Please check again – Omkar T Jan 19 '20 at 11:52
  • Have you tried `query.equaTo("order",myOrder)` instead of `query.equaTo("order",myOrder.getObjectId())`? It should be the right way as you can see in the first example of [this](https://docs.parseplatform.org/android/guide/#relational-queries) link. – Davi Macêdo Jan 20 '20 at 17:37
  • Code might differ a bit.But i did as per documentation.I'm sure there's no mistake in code. It lies in objectId giving null for Offline object – Omkar T Jan 23 '20 at 12:19
  • Have you tried my suggestion? – Davi Macêdo Jan 28 '20 at 02:02

1 Answers1

0

A somewhat working solution for me is:

when setting pointer of Order in OrderItem-s

instead of

orderItem.put("order",myOrderObject)

i use

String randomId = generateRandomString()
myOrderObject.put("temp_orderOfflineId",randomId)
orderItem.put("order_id",randomId )

and in query instead of

orderItemquery.equaTo("order",myOrder.getObjectId())

i use

query.equaTo("order_id",myOrder.getString("temp_orderOfflineId"))

I use this approach This later makes sync with server hard,very hard.

Waiting for better solution

Omkar T
  • 755
  • 8
  • 19