Inder R Singh
Inder R Singh

Reputation: 652

Fields must be specified with a type function error - Keystone

What i want to achieve in KeyStone

  1. I have labConfigs table which looks like below. For each item of LabConfigs table i want to store "UserauthLevel" in Domain table.

    So that's i want to create "Array of boolean Object " in domain table. Below is code for same.

        ****************LabConfigs***********************
        var LabConfigs = new keystone.List('LabConfigs');
    
        LabConfigs.add({
         configName: {type: Types.Text, required: true, initial: true, index: true},
         description: {type: Types.Text, required: true, initial: true, index: true},
         image: {type: Types.Text, required: true, initial: true, index: true},
         type: {type: Types.Text, required: true, initial: true, index: true},
         version: {type: Types.Text, required: true, initial: true, index: true},
        });
        ************************************************
    

    Below is my code for Domain table :-

        **************************Domain table******
    
         var Domain = new keystone.List('Domain');
         Domain.add({
          domainName: {type: Types.Text, required: true, initial: true, index: true},
         labConfigs :{type: Types.Relationship, ref: 'LabConfigs',required: false,many: true},
         userauthlevel:[{ type: Types.Boolean}]
         });
        Domain.defaultColumns = 'domainName';
        Domain.register();
    

    But after running this throw it give me error :-

       throw new Error('Fields must be specified with a type function');
        ^
    

    To solve this problem i tried following code in domain table

        Domain.schema.add ({
               userauthlevel :
                          [{
                          type: Types.Text
                         }]
             });
    

    but this also not help.

    Any suggestions how to solve this problem i know it might work in mongoose.

Upvotes: 2

Views: 920

Answers (1)

Shea Hunter Belsky
Shea Hunter Belsky

Reputation: 3238

You're incorrectly specifying an array of booleans for your userauthlevel property. Keystone doesn't have a Boolean Array type, but it has Types.TextArray which you can use to store multiple possible booleans on a document.

userauthlevel: { types: Types.TextArray }

Any array you pass to it is considered an array of strings, so you'd have to convert any stored values to their proper true/false value on your own.

Upvotes: 1

Related Questions