With reference to joins discussed in <https://gist...
# community-help
n
With reference to joins discussed in https://gist.github.com/kishorenc/037314619c3104970ae703b25aff2f51, if I fetch from
CustomerProductPrices
collection, would it fetch the product automatically or would that require a filter clause as well? Currently the examples seem to be mainly about fetching from
Products
collection which doesn't have the reference field.
One more concern is if we can allow a product price to be added before the corresponding product (allow reference to not be enforced during data entry). I got an error when I tried to add the price before the product.
Got a crash when I used a filter clause:-
Copy code
"filter_by":"$ItemCommon(itemNumber:!='')",
h
We'll be adding support for fetching the related product from
CustomerProductPrices
soon. It won't require any filter clause but you'll have to specify
include_fields: $Products(*)
to get all the fields of related product or specific field names.
One more concern is if we can allow a product price to be added before the corresponding product (allow reference to not be enforced during data entry). I got an error when I tried to add the price before the product.
When a document containing a reference field is created, we lookup the referenced collection and store a reference in
foo_sequence_id
field. That's the reason for enforcing the presence of product.
Can you post a minimal example that reproduces the crash?
n
Copy code
// Collection 1 - item_master
{
    "name": "item_master",
    "enable_nested_fields": true,
    "fields": [
        {
            "name": "id",
            "type": "string",
            "index": true,
            "optional": false,
            "sort": true,
            "infix": true,
            "facet": true
        },
        {
            "name": "attrId",
            "type": "string",
            "index": true,
            "optional": true,
            "infix": true,
            "facet": true
        },
        {
            "name": "itemNumber",
            "type": "string",
            "index": true,
            "optional": true,
            "sort": true,
            "infix": false,
            "reference": "items.itemNumber"
        },
        {
            "name": "name",
            "type": "string",
            "index": true,
            "optional": false
        }
    ]
}

// 2nd collection "items"
{
    "name": "items",
    "enable_nested_fields": true,
    "fields": [
        {
            "name": "itemNumber",
            "type": "string",
            "index": true,
            "optional": true,
            "sort": true,
            "infix": false
        },
        {"name": "notes", "type": "string"},
        { "name": "guideType", "type": "int32", "index": true, "optional": false, "sort": false , "infix": false}
    ]
}
Create these 2 collections
Add data to items
Copy code
{
  "itemNumber": "123456",
  "notes": "TEst Item 1",
  "guideType": 1
}
And then to item_master
Copy code
{
  "_id": "abc",
  "itemNumber": "123456",
  "name": "Test Item 1"
}
@Harpreet Sangar On a side note, please also note this is an example of why I need
item_master
to have an item even though
items
collection doesn't have it (given how current join works which can change)
Run this query and you will then see the crash
@Harpreet Sangar Does the above info work for repro? This is from 0.26 rc12
h
I'll update you.
👍 1
n
@Harpreet Sangar Did you get a chance to look at this?
h
Hi @Nikhil Agarwal I used the following commands and could not reproduce the crash
Copy code
curl -k "<http://localhost:8108/collections>" -X POST -H "Content-Type: application/json" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
    "name": "item_master",                                                                                                    
    "enable_nested_fields": true,
    "fields": [
        {
            "name": "id",        
            "type": "string",
            "index": true,
            "optional": false,
            "sort": true,
            "infix": true,
            "facet": true
        },                                  
        {                                                                                                        
            "name": "attrId",
            "type": "string",
            "index": true,
            "optional": true,
            "infix": true,
            "facet": true
        },
        {
            "name": "itemNumber",
            "type": "string",
            "index": true,
            "optional": true,
            "sort": true,
            "infix": false,
            "reference": "items.itemNumber"
        },
        {
            "name": "name",
            "type": "string",
            "index": true,
            "optional": false
        }
    ]
}'

curl -k "<http://localhost:8108/collections>" -X POST -H "Content-Type: application/json" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
    "name": "items",                                                                                                    
    "enable_nested_fields": true,
    "fields": [
        {
            "name": "itemNumber",
            "type": "string",
            "index": true,
            "optional": true,
            "sort": true,
            "infix": false
        },               
        {"name": "notes", "type": "string"},
        { "name": "guideType", "type": "int32", "index": true, "optional": false, "sort": false , "infix": false}
    ]                        
}'

curl "<http://localhost:8108/collections/items/documents/import?action=create>"
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"
-H "Content-Type: text/plain"
-X POST
-d '{"itemNumber": "123456", "notes": "TEst Item 1", "guideType": 1}'

curl "<http://localhost:8108/collections/item_master/documents/import?action=create>"
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"
-H "Content-Type: text/plain"
-X POST
-d '{"_id": "abc", "itemNumber": "123456", "name": "Test Item 1"}'

curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" "<http://localhost:8108/collections/items/documents/search?q=*>\
&filter_by=$item_master(itemNumber:!='')"
This is the response from the API:
Copy code
{
  "facet_counts": [],
  "found": 1,
  "hits": [
    {
      "document": {
        "guideType": 1,
        "id": "0",
        "itemNumber": "123456",
        "notes": "TEst Item 1"
      },
      "highlight": {},
      "highlights": []
    }
  ],
  "out_of": 1,
  "page": 1,
  "request_params": {
    "collection_name": "items",
    "per_page": 10,
    "q": "*"
  },
  "search_cutoff": false,
  "search_time_ms": 0
}
n
That's surprising since it crashed for me twice. I will try again over the weekend and see if I can find a better repro
h
Just check once by using the same curl commands I provided. It could've been an issue that's already fixed.