0

I'm new to KeystoneJS, and I'm having an issue : I'm trying to use createItem() on a relatioship field, after importing a CSV. I turn the CSV's data into a JSON object thanks to csvtojson library, and then creating an Item based on my JSONObject.

Here is my relationship declaration :

project: { type: Types.Relationship, ref: 'Project' },

And here is my project declaration :

name: { type: Types.Text, required: true, index: true, refPath: 'project' }

But when I'm using the createItem() method, here what I have as an error message :

message: 'Relationship Info.project contains an invalid reference: "Test".' }

I hope I've been clear enough for you guys to help me,

Regards.

1 Answers1

0

I finaly found a solution, so I'm giving it to you. Unfortunately, I didn't manage to do it with the existing updateHandler in Keystone Framework. Instead, here what I did :

I used a query to find the id of the object from its name :

var yourTableQuery = query.select('id').exec(function(err, yourTableId)

And then I used it with the mogoose way to create an object :

item = new yourTable.model({ relationship: yourTableId })

And the link is done.

Hope this helps some of you guys !