This is a migrated thread and some comments may be shown as answers.

How to do many-to-many relationship

1 Answer 131 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Teerawat
Top achievements
Rank 1
Teerawat asked on 14 Feb 2014, 02:52 AM
Hi, There

I am developing chat program using the Backend service.
I have created "Room" content type.

Now, one user can be in many rooms and one room can have multiple users as well.
This is a just many-to-many relationship for database.

I am not sure how to accomplish this using Backend service.
Currently, I have done following:

1. create field 'JoinedBy' which is a multiple relation type to  'User' 
2. create field 'RoomId' which is also a multiple relation type to 'Room'

Is this proper design?
Also, to query this I should use PowerField, right?

Thank you very much,

Teerawat










1 Answer, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 14 Feb 2014, 04:02 PM
Hi Teerawat,

Straight to your questions: this design is valid in terms of relating N-to-N items from content types in Telerik Backend Services. A notable difference in Backend Services is that their database management is not a traditional RDBMS, but is document-based (No SQL) and allows you to apply a significant denormalization if needed.

In general, the 'multiple relation' field in Backend Services is an array containing the GUIDs of the related items. It is noteworthy that the integrity of the data should be maintained and assured by some validation logic, either client-side or server-side (cloud code), or both.

The Power fields are a very convenient way to fetch related data. Within a power field expression you can incorporate filtering, sorting, paging and subset of fields expressions, same as in the examples from here. Please note that a query with power fields will return up to 50 items.

A power fields expression could be executed in two ways:
  • by sending a "X-Everlive-Power-Fields" header with the expression
  • by constructing a 'request.powerFieldsExpression' in the Cloud code of a certain content type (in some of the 'before' event hooks)
We'd also suggest to read this forum thread about updating array fields and this blog post about cloud code.

Hopefully, this information will help you get started. If you have further questions do not hesitate to contact us.

Regards,
Anton Dobrev
Telerik
Everlive is now Telerik Backend Services, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
Tags
General Discussion
Asked by
Teerawat
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Share this question
or