How to do many-to-many relationship

2 posts, 0 answers
  1. Teerawat
    Teerawat avatar
    1 posts
    Member since:
    Jan 2014

    Posted 13 Feb 2014 Link to this post

    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










  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 14 Feb 2014 Link to this post

    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)
Back to Top