Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify the primary key of a type? #33

Open
allthesignals opened this issue Sep 21, 2019 · 3 comments
Open

How to specify the primary key of a type? #33

allthesignals opened this issue Sep 21, 2019 · 3 comments

Comments

@allthesignals
Copy link

Hi, I'm using the json-api serializer with this adapter. JSON API serializer throws an error about toString of undefined— it's trying to stringify the id field received from Postgres, but that field is empty because it doesn't exist in the database.

In this adapter, I can get this to work by changing this and specifying my primary key:

const primaryKey = this.keys.primary

I can't figure out how to do this through the public API. Do I need to extend the class to specify a primary key? Would that be the only way to do this?

@allthesignals
Copy link
Author

I guess I also don't know where in the stack this should be a concern... do I need to configure my Postgres adapter to specify which column is the "id" column, or do I need to configure my json-api serializer to point to a specific identifier value?

@allthesignals
Copy link
Author

Here is my options object... it doesn't appear that "query" or "generatePrimaryKey" ever get called:

  adapter: [
    PostgresAdapter, {
      url: process.env.DATABASE_URL,
      typeMap: {
        project: 'dcp_project',
      },
      generatePrimaryKey(type) {
        console.log('generate primary', type);
        return 'dcp_projectid';
      },
      query: function(query, params) {
        console.log(query, params);
        return query;
      },
    },
  ],

@gr0uch
Copy link
Member

gr0uch commented Sep 23, 2019

Hi @allthesignals,

I don't think I considered adding a customization option to map fields to database columns, which is what I think you are asking for. It seems you have a database table where the primary key isn't id and I didn't anticipate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants