In this test it's well exemplified how to do a file upload with Hook
You can set a input[type=file] or a blob to a collection field. It will store the value as a file, and retrieve a URL to you.
@danray0424 considering you have a posts
collection which belongs_to authors
, you could create posts linked to authors like this:
hook.collection('posts').create({
author_id: 1, // By default, foreign keys are always `{parent_collection_name}_id`
name: "Post name"
})
Now, when you query with join (hook.collection('posts').join('author')
) it would return the author object with _id=1
in the response.
Hope this helps, please let me know if you have any other question!
belongs_to
, and both of those have an _id field. Sorry about that. So I create a parent, read its ID, and use that in the create statements for its children. Can do.
belongs_to
relationship defined on books
and a has_many
defined on authors
. I've created a gist to better demonstrate here: https://gist.github.com/endel/36c0d82a02cc2e16ecd1#file-hook-console
hook generate:seed {collection_name}
to generate those entry files, then populating them into the database using hook db:seed
.
I handcrafted my schema.yaml: https://gist.github.com/danray0424/79d9cbbe7b8711ade76b
What's weird now is, I can join from 'registrations' to 'leak_checks' and 'tank_checks', and I CAN join from 'leak_checks' back to 'registrations', but I don't get any join data when I go from 'tank_checks' to 'registrations'. I've probably done something silly, but for the life of me I can't see it.
has_many
attribute is being replaced there. You could use an array of has_many
relations there, like this: https://gist.github.com/endel/5112736e7c95b350197b#file-schema-yaml-L17-L21