Object in database

Options
sbjorklind
sbjorklind Member
edited January 2023 in ? Working with APIs

So I have created an object with different reviews in a database with some information. There is a table reffrence in the object which points to different reviews. There are multible reviews for every day in the database and the different reviews is owned by different users. How do I make it so when the user opens one of the days it only shows their review from that reviews object?

I get back the reviews object but how do I make it so it only returns the review that belongs to the user.

Answers

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Typically, in this scenario your reviews would be tied to a specific user, maybe by an authors field or something like that. That means that we can use a custom query to make sure that the reviews returned only belong to that specific user, typically by user ID (perhaps even the ID of the authenticated user if this endpoint utilizes authentication).

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @sbjorklind - I'd like to understand your database structure a bit more. What table is "reviews_object" a part of? Also I see "reviews_id", what is the schema of the reviews table... I'm trying to see if you have somewhere where the user_id and review_id are linked.


    I personally, would think about having a reviews table, with the text (or whatever data pertains to the review) and a table reference to the user_id. This tends to make it very easy to pull up the specific user's data and is friendly to scaling if there are going to be lots of reviews.

  • sbjorklind
    Options

    The reviews object is inside of my summaries table. The information of every record in the summaries table is the same for everyone except the reviews. So think of it as maybe different dishes on a restaurant which is the same for everyone but different users have written different reviews for that same dish, and the user can only see their review. So I figured creating a object for the reviews with a table reference to my reviews table would be a good idea.

    As you can see here the reviews are linked to a user.

    Every user also has their reviews linked.

    So I'm just wondering how you would make it so the user only sees their review from the reviews object.

    Thankful for answers!