81920

Relational Query in Parse

Question:

I have 4 classes in Parse. I am using JavaScript.

1) Rangoli - Main item objects 2) Categories - List of all categories 3) Users - List of all users 4) ItemCategories - List of categories that each items are assigned

Below is the structure of all classes.

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/gQxcX.jpg" data-original="https://i.stack.imgur.com/gQxcX.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Now I am trying to get the following details in a single query.

1) User - Name, email, avatar 2) Rangoli - filename, createdAt 3) Categories - name

This is the JavaScript code that I tried.

var Rangoli = Parse.Object.extend("Rangoli"); var ItemCategories = Parse.Object.extend("ItemCategories"); var query = new Parse.Query(ItemCategories); var innerQuery = new Parse.Query(Rangoli); innerQuery.matchesQuery("category", query); query.find({ success : function (data) { console.log(JSON.stringify(data)); }, error : function (e) { } });

With the above JavaScript code, I am getting the record of ItemCategories record and not all the columns of all pointer class like Categories, User, Rangoli.

Answer1:

You can include related objects in the results of a query by using the <a href="https://www.parse.com/docs/js/api/symbols/Parse.Query.html#include" rel="nofollow">include</a> method. e.g.

var ItemCategories = Parse.Object.extend("ItemCategories"); var query = new Parse.Query(ItemCategories); query.include("item"); query.include("category");

You can also use this to get objects nested at multiple levels, e.g., query.include(["category.rangoli"]); but from your data model screenshot I can't see a way to include the Rangoli data with the relationships you have set up.

Recommend

  • Where these are stored?
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Find group of records that match multiple values
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • How do I access an unhandled exception in an MVC Error view?
  • GridView breaks while scrolling
  • Jackson Parser: ignore deserializing for type mismatch
  • How to Cache Real-time Data?
  • How to use RequestBodyAdvice
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • Email verification using google app script and google forms
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Q promise. Difference between .when and .then
  • Email format validation in mvc3 view
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Master page gives error
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Incrementing object id automatically JS constructor (static method and variable)
  • Does CUDA 5 support STL or THRUST inside the device code?
  • sending/ receiving email in Java
  • Redux, normalised entities and lodash merge
  • When should I choose bucket sort over other sorting algorithms?
  • Hazelcast - OperationTimeoutException
  • Display Images one by one with next and previous functionality
  • To display the title for the current loaction in map in iphone
  • Do create extension work in single-user mode in postgres?
  • Akka Routing: Reply's send to router ends up as dead letters
  • AT Commands to Send SMS not working in Windows 8.1
  • Matrix multiplication with MKL
  • SQL merge duplicate rows and join values that are different
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • using HTMLImports.whenReady not working in chrome
  • How do I configure my settings file to work with unit tests?
  • Authorize attributes not working in MVC 4
  • Is it possible to post an object from jquery to bottle.py?
  • EntityFramework adding new object to nested object collection
  • Busy indicator not showing up in wpf window [duplicate]
  • Unable to use reactive element in my shiny app
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF