Areeba Ayub
12/17/2024, 7:23 AMi ran into a scenario related to references/joins in typesense,
my scenario is get all the users with their cars. which could be done in laravel in that simple way below using one to many joins,
$searchParameters = [
'per_page' => 250,
'sort_by' => 'scheduled_date:asc',
'filter_by' => '$cars(id:*)',
'q' => $searchQuery,
'include_fields' => '$cars(*),
'query_by' => 'lead_id',
];
using this i get all the users with their cars (one to many).
But now i have to apply filter that get all the users against which one its car has Booked status. so when i am doing it: 'filter_by' => '$cars(status:Booked)', it get user only one car, but i want to get all the cars.
Desired Result is:
$result = [{
"id": "user1",
"cars": [
{ "id": "car_1", "status": "Booked" },
Copy code{ "id": "car_2", "status": "Available" }
]
}]
Result i am getiing
$result = [{
"id": "user1",
"cars": [
Copy code{ "id": "car_1", "status": "Booked" }
]
}]Can we do something like this? i will appreciate your help, Thankyou
Fanis Tharropoulos
12/17/2024, 8:01 AMhasBooked
. You set that to true if the user has a car booked, and then add that filter to the JOIN conditionAreeba Ayub
12/17/2024, 8:16 AMFanis Tharropoulos
12/17/2024, 8:18 AMAreeba Ayub
12/17/2024, 8:20 AM'filter_by' => '$cars(status: AnyAppliedFilter )',
if user has any car that matches the result then bring that user with all of its cars
Fanis Tharropoulos
12/17/2024, 8:24 AMHarpreet Sangar
12/17/2024, 10:59 AMfilter_by: $cars(status:Booked)
and collect all the user_ids that are returned.
• Then send filter_by: id:[<ids from first step>] && $cars(id:*)
There is no way to get the details of all the cars where at least one car has status Booked in one query.Areeba Ayub
12/19/2024, 12:35 PM