Last active
February 17, 2016 20:31
-
-
Save endel/36c0d82a02cc2e16ecd1 to your computer and use it in GitHub Desktop.
hook: Example configuration using `belongs_to` / `has_many` relationships and eager-loading. http://github.com/doubleleft/hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hook-ext/seeds/books.yaml | |
# Generated through command `hook generate:seed books` | |
# | |
# Seed for books | |
# | |
truncate: true | |
data: | |
- _id: 1 | |
author_id: 1 | |
name: Book one | |
genre: programming | |
- _id: 2 | |
author_id: 1 | |
name: Book two | |
genre: programming |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client: javascript> hook.collection('authors').join('books').then() | |
┌─────┬──────────────┬──────────────────────────────────────────────────────────┐ | |
│ _id │ name │ books │ | |
├─────┼──────────────┼──────────────────────────────────────────────────────────┤ | |
│ '1' │ 'Author one' │ [ Object { │ | |
│ │ │ _id: '1', │ | |
│ │ │ created_at: Wed Feb 17 2016 20:19:48 GMT+0000 (GMT), │ | |
│ │ │ updated_at: Wed Feb 17 2016 20:19:48 GMT+0000 (GMT), │ | |
│ │ │ name: 'Book one', │ | |
│ │ │ isbn: '', │ | |
│ │ │ genre: 'programming', │ | |
│ │ │ author_id: '1' }, │ | |
│ │ │ Object { │ | |
│ │ │ _id: '2', │ | |
│ │ │ created_at: Wed Feb 17 2016 20:19:48 GMT+0000 (GMT), │ | |
│ │ │ updated_at: Wed Feb 17 2016 20:19:48 GMT+0000 (GMT), │ | |
│ │ │ name: 'Book two', │ | |
│ │ │ isbn: '', │ | |
│ │ │ genre: 'programming', │ | |
│ │ │ author_id: '1' } ] │ | |
├─────┼──────────────┼──────────────────────────────────────────────────────────┤ | |
│ '2' │ 'Author two' │ [] │ | |
└─────┴──────────────┴──────────────────────────────────────────────────────────┘ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hook-ext/schema.yaml | |
# | |
# 'books' schema | |
# | |
books: | |
lock_attributes: true | |
attributes: | |
- name: name | |
type: string | |
- name: isbn | |
type: string | |
unique: true | |
- name: genre | |
type: string | |
relationships: | |
belongs_to: authors | |
# | |
# 'authors' schema | |
# | |
authors: | |
attributes: | |
- name: name | |
type: string | |
relationships: | |
has_many: books |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment