Basic query filter

Options

Hey there, for most of you, this is pretty obvious question, but as a beginner I've burned too much time on researching this, so here I am.

I have 2 tables. Rating request table and Ratings table. On my frontend I want to display only requests type1 that have less than 30 ratings and only rating requests type 2 that have less then 50 ratings.

Request Type is a separate column in Requests table.
How can I customize Get requests api call so it will be filtered based on these criteria?

Thanks

Answers

  • arturosanz
    arturosanz Member ✭✭
    edited September 2023
    Options

    I suggest to do it simple.

    1. Add a counter integer field to the requests table.
    2. Keep track of the number of ratings added/deleted related to each request by incrementing/decrementing each request counter field.
    3. QueryAllRecords WHERE (type=type1 AND counter<30) OR (type=type2 AND counter<50)

  • NameCheck
    Options

    Thanks arturosanz, I was just wondering whether it could be possible without adding new column to request table.

  • arturosanz
    arturosanz Member ✭✭
    Options

    It would be possible with two subsequent queries, one in ratings first and one in requests using the intersect filter in the second query with the results of the first one. But the intersect filter is not available in the QueryAllRecords WHERE clause yet.

    Evals and aggregates are another more option. Perform a query on ratings joining the request, then add an eval aggregated field and sort the results by that field. Then loop through the results and remove from the array the ones that don't match your conditions.