Hi! I have a denormalized set of `products` with t...
# community-help
d
Hi! I have a denormalized set of
products
with the columns
category_1_id
,
category_2_id
,
category_3_id
. Inside the document I set the reference like that (Laravel Scout)
Copy code
['name' => 'category_1_id ', 'type' => 'string', 'reference' => 'categories.id'],
['name' => 'category_2_id', 'type' => 'string', 'reference' => 'categories.id'],
['name' => 'category_3_id', 'type' => 'string', 'reference' => 'categories.id'],
inside my search statement I now try to include all categories. However it only includes the first:
Copy code
include_fields: $products(*, $categories(*, strategy: nest_array))
what am I missing? I'm also using a filter_by:
Copy code
(id: * || $products(price:=100))
Thanks in advance!
Does typesense support working with a denormalized table? Tried around a little bit, but it always only includes the first reference. All other references on the same relation aren't included.
j
CC: @Harpreet Sangar
h
@Dominic We only support one reference field per collection at the moment.
There are two workarounds. • You can have one field like:
'name' => 'categories', 'type' => 'string[]', 'reference' => 'categories.id'
containing all the categories. • You can add intermediary collections like:
Copy code
products -> category_1 -> categories
products -> category_2 -> categories
products -> category_3 -> categories
Now you'll be able to do
include_fields: $products(*, $category_1($categories(*, strategy: merge)), $category_2($categories(*, strategy: merge)), ...)
🙌 1