Monday, 26 January 2015

A new type of keystonejs ObjectArray (sub object collection)



As people are discussing about keystone issue 153 (https://github.com/keystonejs/keystone/issues/153), Keystonejs users expect to have a sub-collection or sub object list/array.

Mongodb is a new database, which does not like traditional database. We can put sub-object and sub-collection(sub-array) into a table(to avoid confuse you I will keep calling mongodb collections as table). However Keystonejs does not support that, Keystonejs still suggest to use reference to connect to another table.

But a lot of users want have the functionality. So this post is aiming to explain How to implement sub objectArray in keystonejs.


Is that what you want? :



I hope this is what you want!!

How to implement it:



You almost got it, just one last step:

Put one more dependency into your package.json file:

"keystoneplus":"~0.0.1"



The real last step:

run:

npm install

then you can start your application by:

node keystone.js


Example code:

https://github.com/wangpingsx/keystoneplus_example



Source code of this solution:


As you can see, my solution is all in a nodejs package -- keystoneplus. You can find the source code here:  https://github.com/DigitalInnovation/keystoneplus




Further read:

For more technical depth of how this sub-collection was implemented, please click below link hardly:

http://baiduhix.blogspot.co.uk/2015/01/a-new-type-of-keystonejs-objectarray_26.html



Acknowledge:


Massive thanks to M&S for sponsoring this project.


Of cause many thanks to all contributors of Keystonejs!!!!









































No comments:

Post a comment