0

My problem is the following:

I have a website with products which contains ratings. I have an element-api endpoint to get the products. I want to sort the products based on the average rating or the amount of reviews. Normally I would join the rating table in the entry query to get access to the review info. Is this possible with element-api?

 'products/category/<categoryId>/' => function($categoryId) {
            return [
                'elementType' => Entry::class,
                'criteria' => [
                                'section' => 'product',
                                'productCategory' => $categoryId, 
                                'order'   => $ordening, 
                                'join' => [
                                            'LEFT JOIN', 
                                            'qarr_reviews', 
                                            'entries.id = qarr_reviews.id'
                                          ]
                              ],
                'one' => false,
                'elementsPerPage' => 36,
                'transformer' => function(Entry $entry){
                         return [         
                             ....
                         ];   
                }
            ];
},
...

If I add the join to the criteria like above I get the following error:

{"error":{"code":404,"message":"A join clause must be specified as an array of join type, join table, and optionally join condition."}}

What is the way something relatively simple like this is normally done with element-api?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.