Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
WebKits
@WebKits
Hi
Endel Dreyer
@endel
@WebKits hey!
WebKits
@WebKits
got any good repo
for php
And frameworks
Check out my start kit https://github.com/WebKits
Endel Dreyer
@endel
@WebKits what kind of php repos are you looking for?
WebKits
@WebKits
Any good one
Frameworks
IDES
ide
WebKits
@WebKits
And much more
Thanks man
Gabriel Laet
@gabriel-laet
Hello
João Mosmann
@JoaoMosmann
Aye!
Wagner Moschini
@wagnermoschini
hue br
Endel Dreyer
@endel
hi there
Renato Stefani
@renatosas
amazing work folks!
sergio freitas
@sergiofreitas
hello
I discovered this incredible project today, it fits perfectly in my project
do you have a example in js with file upload?
João Mosmann
@JoaoMosmann
Hey @sergiofreitas !

In this test it's well exemplified how to do a file upload with Hook

https://github.com/doubleleft/hook-javascript/blob/23eb48e842ccf014e89daaea5890e733fa93f1db/tests/formdata.html#L53-L71

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
@danray0424
There are examples given for how to query joins. How do I insert a parent record and a few has_many children? I can't find a sample of that anywhere.
Endel Dreyer
@endel
Hi @danray0424, are you using the JavaScript client? There's a few usage examples on these slides here: https://speakerdeck.com/endel/number-tdc2015-know-hook-and-how-to-use-it#60
danray0424
@danray0424
Yes, that's a great example of querying with a join. How do I create with a join?
Endel Dreyer
@endel

@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!

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, ... }).