question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relationship data and foreign keys?

See original GitHub issue

Is there any way I could include data from other tables when I only have the ID?

Example of what I’m expecting to achieve:

import { Reference } from "./types"

// Records should be added here to be indexed / made searchable
const references: Array<Reference> = [
 {
   collection: "comments",
   index: "comments",
   include: ["text", "user_id"],
 },
]
export default references

Instead of indexing user_id I would like it to get the actual user document based on the ID from users collection.

Is this possible?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
acupofjosecommented, Feb 12, 2021

Ah, one more modification then! You’ll have to await the calls in FirestoreHandler.ts

So anywhere there is:

body = this.reference.transform.call(/*...*/)

it should be changed to:

body = await this.reference.transform.call(/* .... */)

I think that oughtta do it

0reactions
acupofjosecommented, Feb 21, 2021

Sorry for the delay on this!

It seems like a better idea would be to use the onItemUpserted property in references and the add an update_by_query from elasticsearch. (You’ll have to pull the latest commit on the repo to have access to that)

Something resembling (I’m not sure what your actual structure is):

{
  collection: "comments",
  index: "comments",
  include: ["text", "user_id"],
  transform: async (data, parent) => {
    // Transformation from Firestore happens here
  },
  onItemUpserted: async (data, parent, esClient) => {
     await esClient.updateByQuery({
       index: 'comments',
       refresh: true,
       body: {
       script: {
          lang: 'painless',
          source: 'ctx._source["user_name"] = data.user.name
        },
        query: {
          match: {
            user_id: data.user_id
          }
        }
      }
    })
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a database foreign Key? A beginner's tutorial
A foreign key is a column (or group of columns) used in a relational database to link data between tables. This tutorial will...
Read more >
Relational Databases: Foreign Keys - MariaDB Knowledge Base
Relational Databases: Foreign Keys ... You already know that a relationship between two tables is created by assigning a common field to the...
Read more >
Dimensional modeling: Primary and foreign keys - IBM
The primary key/foreign key relationships between tables in a star or snowflake schema, sometimes called many-to-one relationships, represent the paths along ...
Read more >
Create and manage foreign key relationships | Cloud Spanner
This page describes how to manage foreign key relationships in your database. Foreign keys allow you to define relationships between tables.
Read more >
What is a foreign key? (With SQL examples) - Cockroach Labs
Foreign keys put the “relational” in “relational database” – they help define the relationship between tables. They allow developers to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found