Support Topics Documentation Slack YouTube Blog

Relationship


(SnakeEyes) #1

Hello
Let’s say I have the following DB schema (Which I am open to change by the way)

User:
ObjId
userName
Name
likesRel(relationShip to Likes 1:many)
Age

Likes:
ObjId
commentsRel(relatiohsip to Comments 1:1)
date

Comments:
ObjId
title
content

I assume that I don’t need to add PK and FK across the tables because this is what the concept of relationships are.
The above bascially shows you users who made likes on comments.
Now based on the above, I need the following:

  • Given user Id, get likes and the comments being liked.
  • Give me all the likes and comments of all the users whose age is less than 25
  • for a specific comment, get me all the users who liked it

How do you advise handling this?


(Oleg Vyalyh) #2

Hi.
Try these ones:

  1. Users[relToLikes].objectId = ‘<user’s-object-id>’ // relToLikes - is the relation name
  2. Users[relToLikes].age < 25
  3. likes[relToComments].Users[relToLikes].objectId = ‘<user’s-object-id>’

(SnakeEyes) #3

Thanks Oleg, I understand 1 and 2. But for 3, I need to get the users so how can I even supple user object id?


(Oleg Vyalyh) #4

Really, I wrote the request in the reverse.
Just write in in direct way relToLikes.relToComments.objectId = ‘comment-objectId’

Also, please investigate our documentation:
https://backendless.com/docs/android/data_search_with_where_clause.html
There are number of examples similar to yours.


(SnakeEyes) #5

Hi Oleg,
Yes I checked the documentation. So I see you are using the subqueries as opposed to the relationship api. The thing that subqueries returns objectId of the rows of interest not the full data (all the columns of that row). Also in my query 2 above, I am interested in data from 2 tables at once ( which is likes and comments). I think I missunderstanding something. Maybe I need to rereview the docs again