meteor-astronomy icon indicating copy to clipboard operation
meteor-astronomy copied to clipboard

Keys with dots

Open JulianKingman opened this issue 8 years ago • 3 comments

I'm getting this error:

Exception while invoking method 'login' Error: key profile.Leagues must not contain '.'

I think it's related to this recent change: https://github.com/meteor/meteor/issues/3786

JulianKingman avatar Mar 16 '17 18:03 JulianKingman

OK, I think this is actually because I'm trying to add a nested field in a behavior, ideas for that? It looks like this right now:

fields: {
        [behavior.options.keyStore]: {
          type: [String],
          optional: true,
          default() {
            return behavior.options.type === 'many' ? [] : '';
          },
        },
      },

In my test case, I want the field to be profile.Leagues

JulianKingman avatar Mar 16 '17 19:03 JulianKingman

The short answer will be to skip this. I can create a nested object like this:

const field = _.set({}, behavior.options.keyStore, {
      type: behavior.options.type === 'many' ? [String] : String,
      optional: true,
      default() {
        return behavior.options.type === 'many' ? [] : '';
      },
    })
...
fields: {
  ...field
},

But I get an error about reading prototype of undefined (something to do with types).

JulianKingman avatar Mar 16 '17 19:03 JulianKingman

For setting nested fields you have doc.set method which works similarly to _.set but it has more features like ability to cast values, set default values etc. I can't help you with you problem as I have to little information. Moreover as I said in another issue, you should rather create module not behavior if you want to implement relations.

lukejagodzinski avatar Mar 17 '17 07:03 lukejagodzinski