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 mapping in update scripts

See original GitHub issue

After many months away from Keystone, I’m back and redoing one of my earlier sites where Keystone was only used for part of the site. (and I wanted to play with the new shiny bits!)

However, I’m having issues with the create scripts. So I was reading #334 and decided that I liked what @LegitTalon was suggesting and thought I’d give it a go.

My issue is in the update scripts how can I setup a User and populate a relationship (many) field type?

So I have two update scripts:

File: ./updates/0.0.1-roles.js

exports.create = {
    Role: [
        { name: 'Member' },
        { name: 'Administrator' },
        { name: 'Speaker' }
    ]
};

File: ./updates/0.0.2-admins.js

exports.create = {
    User: [
        { 'name.first': 'Admin', 'name.last': 'User', email: 'admin@keystonejs.com', password: 'admin', isAdmin: true, roles: [ 'Member', 'Administrator' ] }
    ]
};

And the output is:

------------------------------------------------
Successfully applied update 0.0.1-roles.
------------------------------------------------
Applying update 0.0.2-admins...
------------------------------------------------
Update 0.0.2-admins failed with error:
{ type: 'invalid ref',
  srcData:
   { 'name.first': 'Admin',
     'name.last': 'User',
     email: 'admin@keystonejs.com',
     password: 'admin',
     isAdmin: true,
     roles: [ 'Member' ],
     __doc:
      { __v: 0,
        isAdmin: true,
        password: '$2a$10$u7xyETeUCeDUd2foAfhV2uGxH4wi9IygADLZPwtkk6wcU0dsPk0zW',
        email: 'admin@keystonejs.com',
        roles: [],
        name: { last: 'User', first: 'Admin' },
        _id: 54a3db35b1342dd31c34fd02 } },
  message: 'Relationship User.roles contains an invalid reference.' }

Which seems to be from ./lib/core/createItems.js#L225

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
moi-jcommented, Apr 18, 2018

Any news about this? Did anyone solve it for v4?

4reactions
Twansparantcommented, Mar 15, 2018

This method does not seem to work anymore in v4… Any workarounds for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Mapping | Property and Relationship Mapping ... - eduCBA
In this article, we will study how we can map the tables and relationships present in SQL to the objects and their relationships...
Read more >
Creating Mapping Scripts - Oracle Help Center
This type of mapping enables you to specify source members mapped to script expressions rather than to hard-coded target members. Target values are...
Read more >
Transform script to upload data in to relationship table
Hi Community, I need help with transform scripts. I have a 1,00000 records data that need to be uploaded on to 'rel_ci' table....
Read more >
export relational model changes as a SQL script - LLBLGen Pro
To do so, you have to export the relational model data as a Database Schema Update Script. You can also decide to use...
Read more >
Relationships in SQL - Complete Guide With Examples
A relationship between two database tables presupposes that one of them has a foreign key that references the primary key of another table....
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