7

How can I create the array of strings in Keystone.js Database ODM? I have to create new model with single field and make a many:true relationship with him only?

Tolsi
  • 656
  • 9
  • 20
  • possible duplicate of [How to add virtual property of type Array using Keystone.js?](http://stackoverflow.com/questions/22063884/how-to-add-virtual-property-of-type-array-using-keystone-js) – Tolsi Mar 21 '14 at 07:05
  • Some documentation about the solution of this (Types.TextArray) is avalable on Github https://github.com/keystonejs/keystone/tree/master/fields/types/textarray – edmundo096 Mar 25 '17 at 06:33

1 Answers1

20

There is a field type for this:

Things.add({
  manyStrings: { type: Types.TextArray }
});

There is a similar field for numbers called Types.NumberArray.

If you want something more sophisticated, your best bet is creating a separate List and using the Relationship field.

Jed Watson
  • 20,150
  • 3
  • 33
  • 43
  • Can we use array of other types? like Types.NumberArray – vinesh Apr 14 '15 at 05:49
  • 12
    How come the documentation doesn't mention Types.TextArray? – ChrisRich Sep 23 '15 at 10:21
  • 1
    @JedWatson the lack of documentation is killer! – r3wt May 11 '16 at 16:16
  • 2
    +1 @ChrisRich Docs could be much better. Check `project/node_modules/keystone/fields/types` to see [all types](http://imgur.com/a/4aLwc). – Mikel Nov 18 '16 at 09:22
  • @ChrisRich At the time of your comment, the TextArrays are not in the current old-but-stable v0.3.x documentation, while the Array types are of the v4.0.0-beta.4 or beta 5. There is already some documentation about this on Github only https://github.com/keystonejs/keystone/tree/master/fields/types/textarray – edmundo096 Mar 25 '17 at 06:32