Support Topics Documentation Slack YouTube Blog

Do two ways relationship all the time?


(SnakeEyes) #1

Hello
Is it bad idea to make all tables relations 2 ways?
So if I have A related to B then I make B related to A as well.
This way I can always get A form B or B from A (especially in a heavy relational style app).

Does this make sense or am I missing something?
Thanks


(Mark Piller) #2

Hello,

It is excessive to make two way relationships for the reason that once you establish a relationship in backendless, you can do data retrieval both ways (getting Bs from A and then getting A from any of the Bs).

Regards,
Mark


(SnakeEyes) #3

Oh we can get backward relations? I read in one of the posts that this is not possible and thus my question. Would you mind sharing how?
For example let’s have Users table and Tags table. Let’s say users table has column called “followingTags” where it is 1:N to Tags table.

I know how to (using 1 or 2 steps retrieval) :

  1. Get all the Tags that user ABC follows.
  2. Get all the Users and all the tags that these users follows

But how can I get
All the users that follow Tag1?


(Mark Piller) #4

that would be quite easy - you need to use the following where clause and query the Users table:

followingTags.objectId = 'objectId-of-the-required-tag'

OR

followingTags.tagName = 'name-of-the-tag'

Hope this helps.

Mark


(SnakeEyes) #5

YES it helps. Thank you very much