Skip to content

Instantly share code, notes, and snippets.

@jde
Last active October 7, 2016 18:42
Show Gist options
  • Save jde/e64306c85b4345701cba33b2e786241a to your computer and use it in GitHub Desktop.
Save jde/e64306c85b4345701cba33b2e786241a to your computer and use it in GitHub Desktop.
Proposed item relationship format for views
// This is a proposed format for representing relationsips in items when
// they are rendered into views. This optimizes both for transport and
// lookup efficiency on the front end.
// compacting rels into arrays of keys in hashes with the name of the rel as the key will:
// 1) allow lookups on the fe without needing to iterate
// 2) compact the data into the tightest possible (with json at least) format for transport
{
_id: "23423423",
type: "user",
data: {
name: "fred"
},
rels: {
"wrote": ['23423423', '23423423', '23423423', '23423423'],
"follows": ['2342ewr23', '2342ewr23']
}
},
{
t: "comment",
d: {
body: "The quick brown fox WASN'T FAST ENOUGH"
},
rels: {
"author": ['23423423'],
"context": ['32l4j2l3k4j']
}
}
...
@gabelula
Copy link

gabelula commented Oct 4, 2016

Great! Are you thinking on model this same way the comments on comments relationships?

@davidgljay
Copy link

Yes. so a comment might have:

rels : {
   'replies': ['abcd', 'qaaa', 'aclu']
}

or

rels: {
  'replyTo': ['abcd']
}

I'd love to check in about how to best provide the info necessary for these relationships. For example: it's easy for me to post new comments with a 'replyTo' field, I want to make sure I'm giving you all what you need to populate the 'replies' relationship in the parent comment appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment