some questions can't find answer in documentation.
i'm trying structure this:
node: id: '1sdf12asd123', name: 'node1', history: [ ts: 234234234234, data: { 'foo': 'bar' } ], ...
so each individual node, has many history items. , want able push
new data that, without overwriting anything.
now, don't want store under each node, rather in seperate document, think embedsmany suitable this:
{ "name": "node", "plural": "nodes", "base": "persistedmodel", "idinjection": true, "options": { "validateupsert": true }, "properties": { "name": { "type": "string" } }, "validations": [], "relations": { "history": { "type": "embedsmany", "model": "history", "foreignkey": "historyid" } }, "acls": [], "methods": {} }
so history simply:
{ "name": "history", "base": "persistedmodel", "idinjection": true, "properties": { "ts": { "type": "date" }, "data": { "type": "object" } }, "validations": [], "relations": { "node": { "type": "belongsto", "model": "node", "foreignkey": "nodeid" } }, "acls": [], "methods": {} }
i'm not sure foreignkey part right, i've tried lot of different combinations, , 1 seems logical.
the history model not public, not exposed endpoint. , want utilize relations as possible, rather have seperate endpoint.
main issue here use nodes.history.add()
described here.
but i've tried different methods remote methods
operation hooks
, can't find helper methods mentioned. there's no code example found this.
partly think because documentation @ times not clear or assumes degree of knowledge how perhaps other api-frameworks work. , i've read every page of documentation found. (one example core concepts
page links deprecated model hooks
page.)
what i'd know:
- is idea of using
.add()
right push data on model, , have loopback manage should store it, when query node i'dhistory
items, unless prevent on server side (because wouldn't want every request node data itself. - is idea create separate document each history item, nodeid in it, or better make 1 histoy item per node, , store history inside them? main issue me is, how
push
data, without overwriting anything, , perhaps utilizingtimestamp
key? - does
history
model need know relationnodes
belongsto
or oblivious , still havenodes
.add()
each history item it?
if understand problem correctly, instead node
hasmany
history
. use methods generated relation :
to create new history using relation
post api/node/{nodeid}/histories/
you should able create multiple instances of history single post request writing json data appropriately
{ { ts: 26283829879 }, { ts: 5335329923 } }
to single histories node
get api/node/{nodeid}/histories/{historyid}/
you can histories node, edit history of given node, etc.
is helpful ?
see strongloop docs hasmany relations.
Comments
Post a Comment