Relationship mapping in update scripts
See original GitHub issueAfter 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:
- Created 9 years ago
- Comments:13 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any news about this? Did anyone solve it for v4?
This method does not seem to work anymore in v4… Any workarounds for this?