From 249294a657feae2eea38a3a442bfc50c1e69827b Mon Sep 17 00:00:00 2001 From: Harpreet Sangar Date: Tue, 17 Jan 2023 09:49:17 +0530 Subject: [PATCH] Index `foo_sequence_id` field that stores sequence_id of referenced document. --- src/field.cpp | 7 +++++++ test/collection_join_test.cpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/field.cpp b/src/field.cpp index 814c3c54..d29e909a 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -697,6 +697,13 @@ Option field::json_field_to_field(bool enable_nested_fields, nlohmann::jso field_json[fields::reference]) ); + if (!field_json[fields::reference].get().empty()) { + the_fields.emplace_back( + field(field_json[fields::name].get() + "_sequence_id", "string", false, + false, true) + ); + } + return Option(true); } diff --git a/test/collection_join_test.cpp b/test/collection_join_test.cpp index 0065e8ae..81a311bb 100644 --- a/test/collection_join_test.cpp +++ b/test/collection_join_test.cpp @@ -92,5 +92,10 @@ TEST_F(CollectionJoinTest, SchemaReferenceField) { ASSERT_EQ(schema.at("customer_name").reference, ""); ASSERT_EQ(schema.at("product_id").reference, "Products.product_id"); + ASSERT_EQ(schema.count("product_id_sequence_id"), 1); + + auto field = schema.at("product_id_sequence_id"); + ASSERT_TRUE(field.index); + collectionManager.drop_collection("Customers"); } \ No newline at end of file