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.

Schema response does not contain foreign keys

See original GitHub issue

Hi there, I’m successfully using factories to create multiple records with associated records (as per the website instructions and as shown in the extract below).

However, the return schema.logEntries.all(); produced records do not contain the logLineIds field with the foreign keys. I am 100% they exist in the db because when I use the commented last-line in below example it does yield the expected result.

Am I missing something obvious here or am I expecting something that is not supported?

    models: {
      logEntry: Model.extend({
        logLines: hasMany()
      }),
      logLine: Model.extend({
        logEntry: belongsTo()
      }),
    },

    factories: {
      logEntry: logEntryFactory,
      logLine: logLineFactory,
    },

    seeds(server) {
      server.createList('logEntry', 3).forEach(logEntry => {
        server.createList('logLine', 2, { logEntry })
      })
    },

    routes() {
      this.namespace = "api"; // mock all cals to `/api`
      this.timing = 1200; // simulate slow networks

      this.get("/log-entries", (schema) => {
        return schema.logEntries.all();
        //return {logEntries: server.db._collections[2]._records}
      });
  }

However, when I

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
richardmarbachcommented, Sep 1, 2020

I’m having a similar issue to @benjamindavid. The response I’m trying to mock:

[
  {
      id: 1,
      username: 'user1',
      comments: [{
            id: 2,
            text: 'my comment',
            user_id: 1
      }]
  }
]

I’ve setup the serializer to always include id’s and embed the includes, but the user_id isn’t included in the response:

Serializer.extend({
    serializeIds: 'always',
    root: false,
    embed: true,
})
[
  {
      id: 1,
      username: 'user1',
      comments: [{
            id: 2,
            text: 'my comment'
      }]
  }
]

Is there a way to customize the serializer to include the foreign id in the embedded resource?

0reactions
richardmarbachcommented, Sep 1, 2020

If I’m understanding the behavior correctly, this is currently impossible?

https://github.com/miragejs/miragejs/blob/master/lib/serializer.js#L705

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 common foreign key mistakes (and how to avoid them)
1. Mismatched data types ... When you're using a foreign key to reference a column in another table, the datatypes of both tables...
Read more >
GraphQL schema on Postgres with foreign keys and without ...
Hasura GraphQL Engine allows creating relationships over Postgres tables with or without foreign keys.
Read more >
Unable to create foreign key relationships in the Table Editor
Bug report Describe the bug Unable to create relationships between tables using the 'Add foreign key' function in the table editor.
Read more >
How to list table foreign keys - Stack Overflow
You can do this via the information_schema tables. For example: SELECT tc.table_schema, tc.constraint_name, tc.table_name, kcu.column_name, ...
Read more >
Loose foreign keys - GitLab Docs
Most of our database tables have foreign keys. With the ongoing database decomposition work, linked records might be present on two different database...
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