This message was deleted.
# community-help
s
This message was deleted.
k
Here is some code (uses chance to generate dummy data)
Copy code
const array = (length, items) => Array(length).fill(0).map(items);

await client.collections().create({
  name: "Products",
  fields: [
    { name: "product_idx", type: "string" },
    { name: "product_name", type: "string" },
  ],
});
await client.collections().create({
  name: "Users",
  fields: [
    { name: "user_id", type: "string" },
    { name: "user_name", type: "string" },
  ],
});

await client.collections().create({
  name: "CustomerProductPrices",
  fields: [
    { name: "user_id", type: "string", reference: "Users.user_id" },
    { name: "product_id", type: "string", reference: "Products.product_idx" },
    { name: "product_price", type: "float" },
  ],
});
let products = array(200, () => ({
  product_idx: chance.guid(),
  product_name: chance.sentence({
    words: chance.integer({ min: 1, max: 10 }),
  }),
}));
let users = array(200, () => ({
  user_id: chance.guid(),
  user_name: chance.word(),
}));

let customers = array(200, () => ({
  user_id: users[chance.integer({ min: 0, max: users.length - 1 })].user_id,
  product_id:
    products[chance.integer({ min: 0, max: products.length - 1 })].product_idx,
  product_price: chance.floating({ fixed: 2, min: 1 }),
}));
await client
  .collections("Products")
  .documents()
  .import(products, { action: "create" });
await client
  .collections("Users")
  .documents()
  .import(users, { action: "create" });
await client
  .collections("CustomerProductPrices")
  .documents()
  .import(customers, { action: "create" });
let result = await client
  .collections("Products")
  .documents()
  .search({
    q: "*",
    filter_by: `$CustomerProductPrices(user_id:=${customers[0].user_id})`,
    include_fields: `$CustomerProductPrices(product_price)`,
  });
As is, this query is hanging. If I change "product_idx" to "product_id" (so that referencing field matches), or if I change the collection being searched to "Users", the query works fine.
a
I couldn't add documents to the collection with field referencing another collection. I received this message :
Copy code
Error importing document: Field `category_id_sequence_id` has been declared in the schema, but is not found in the document
field name is category_id for both collections
I found the issue, I was sending a field with the name id
k
@Kanak Arora We've fixed this issue. How are you using Typesense? Happy to share the updated build with you. If you are on Cloud, please DM me your cluster ID.