Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
danray0424
@danray0424
Okay. I didn't make that assumption because after running my schema deploy, I didn't see relationship fields like "author_id" in the database. Is that normal, or do you think there was something wrong with my schema?
Endel Dreyer
@endel
@danray0424 no worries! do you have a belongs_to relationship defined? It should create those foreign keys for you. Maybe you have only has_many defined. Could you share your schema.yaml file?
danray0424
@danray0424
Know what, I take it back. I guess I missed it earlier--my schema.yaml defines a parent entity and two children that are 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.
danray0424
@danray0424
Okay, next question! I have joins working from the child entity to its parent. So book.author.first_name works. What I need is a join that eager-loads a list of child entities from a query on the parent. I want an array called author.books. When I try that, no such element shows up in the data.
Endel Dreyer
@endel
Hey @danray0424, good. Basically you'd need to have a 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
I'm using hook generate:seed {collection_name} to generate those entry files, then populating them into the database using hook db:seed.
danray0424
@danray0424

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.

Endel Dreyer
@endel
@danray0424 I see! What happened is that the 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
There's two ways of doing that on YAML, one of them I left commented on this example
danray0424
@danray0424

Aha! Thanks. YAML isn't really my thing (though I can JSON with the best of them). I'll try that out today.

You might consider adding another child entity to the relationships documentation ("articles" belongs_to "authors", perhaps) to make the example a little more real-world. Few real projects have only one relationship.

danray0424
@danray0424
Okay, I'm making good progress. Next thing I'm bumping into is, I get an error "not implemented" in the console when I try to subscribe to a channel and use the streaming stuff. Is that really a TODO in the JS client, or is there something I'm missing?
Endel Dreyer
@endel
@danray0424 Good to hear! :) The hook.channel() backend is kinda broken (doubleleft/hook#151) I'll dive into it this weekend. It uses Server Sent Events, through http polling
danray0424
@danray0424
Okay, I've broken my relations again. I made a very schematic schema that only dealt with relations. I wrote to the API from javascript, creating a bunch of fields and populating the _id relationship fields. But when I query with a join, I only get the parent entity. The schema is here: https://gist.github.com/danray0424/c05e924113877f9398c3
Endel Dreyer
@endel
Hey @danray0424! Your schema file looks good. One important thing to note is that the related_id fields should use singular, e. g.: hook.collection('registrations').create({ leak_check_id: 1, pressure_test_id: 2, ... }).
Do you mind sharing how you're querying it via JavaScript and the response you're getting? Thanks!
Elena Baklanova
@elvalery
Hi there! Need your help. Can't understand how to move hook db to postgres or how to debug it. I've changed database.php, and now all i get even if I write 'hook logs' is 'Error: bad response' and 'Your IP Address is not allowed to perform this operation. (status 403)'. Is it possible to get some more logs or trace? If I change old database settings back everything is ok.
Elena Baklanova
@elvalery
ah. sry. everything is ok now.
Endel Dreyer
@endel
@elvalery that's ok. Feel free to ask here in case you have any questions!
Elena Baklanova
@elvalery
hey! I was wondering if it's possible to use db transactions inside custom routes?
Endel Dreyer
@endel
hi @elvalery! yes, it is! hook basically uses Eloquent for that, here's an overview of how it works: http://doubleleft.github.io/hook-userguide/The-Basics/Collections/#querying-the-database
The transactions can be used exactly in the same way as Laravel do: https://laravel.com/docs/5.1/database#database-transactions
Elena Baklanova
@elvalery
This message was deleted
thank you! everything is fine now
Elena Baklanova
@elvalery
There is another problem. Seems that I do not understand scheme relations properly. There is easy case: friends collection. I imagine it like a table with an auth_id and friend_id fields. [auth_id, friend_id] must be unique. Both of them must be related to auths collection. Could you please explain how I should describe this kind of collection in scheme.yaml?
Elena Baklanova
@elvalery
and one more question. is it possible to configure routes to be accessible only with specific device keys?
Endel Dreyer
@endel
@elvalery great! good to hear you're getting things done :)
Here you can find the syntax of defining more complex relationships (search for "Complex example") http://doubleleft.github.io/hook-userguide/The-Basics/Schema/, basically you'd need to use different collection and possibly specify the foreign_key/primary_key.
Endel Dreyer
@endel
About the routes, there's no built-in way to restrict that. What is possible is to check the current key being used and abort the request, like this:
if (!Context::getKey()->isBrowser()) {
  throw new Exception("access denied!");
}
Endel Dreyer
@endel
The methods available for checking key type are here: https://github.com/doubleleft/hook/blob/master/src/Model/AppKey.php#L33-L51
santosh
@santoshgistto
hi
Makefile:10: * "Missing npm.". Stop.
on ubuntu machine how to run
getting hook command not found error
Endel Dreyer
@endel
Hi @santoshgistto, you need nodejs installed before running the hook installer. Please let me know if you run into any problems further.