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.

How to use other Model in data source?

See original GitHub issue

I tried to use mongoose

// Model
const Model1 = mongoose.model('col1', Schema1)
const Model2 = mongoose.model('col2', Schema2)


// Data source
export default class Data1 extends MongoDataSource {
  getData1(name) {
    // How to use `Model2`
    return this.model.findOne({ name: name })
  }
}
........................

// Apollo server
...........
dataSources: () => ({
    data1: new Data1(Model1),
    data2: new Data2(Model2),
  }),

How to use Model2 in DataSource1 (Data1)?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
thearabbitcommented, Apr 15, 2020

Very thanks again 👍

1reaction
9at8commented, Apr 15, 2020

You might be able to use context inside the getData method in the Data1 class.

class Data1 extends DataSource {
  getData(x) {
    this.context.dataSources.data2.getData(x)
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How should I model a single entity that has data from multiple ...
Your database has a minimum of three tables, and really should have many more: The first is for the car type, which really...
Read more >
Using Multiple Data Sources in Your Model - IBM
You can create more powerful views of your data by adding multiple data sources to a single model, allowing you to combine disparate...
Read more >
Relationships between tables in a Data Model
A relationship is a connection between two tables of data, based on one column in each. A workbook can store each piece of...
Read more >
Data Modeling with Multiple Data Source Types - InetSoft
Launch the Data Modeler from the Windows 'Start' menu: Start → All Programs → Style Intelligence → Data Modeler. · Click the 'New...
Read more >
How To: Import & merge Data Models / Data Sources / Views ...
You can use this technique to merge as many data models as you like, even the same target database type (e.g. multiple instances...
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