faustinoaq changed the topic of #amber to: Welcome to Amber Framework community! | https://amberframework.org | Developer happiness, productivity and bare metal performance | GH: https://github.com/amberframework | Docs: https://docs.amberframework.org | Gitter: https://gitter.im/amberframework/amber | IRC Logger: https://irclog.whitequark.org/amber | Amber::Server.start
_whitelogger has joined #amber
<FromGitter> <vectorselector> noobie granite question: how is one to recursively get all of an Model's child-related Models, for serialization, for example.
<FromGitter> <vectorselector> I see the method of the child_id key for mapping purposes, but then I can't just access Model.children without getting them somehow. Do I have to manually make some other object and copy all the things in there? What do people typically do?
<FromGitter> <vectorselector> I mean, template mapping and directly loading a javascript object one crystal loop at a time is ok for the template, but for an xhr, I must spit it all out in one blob, typically json, etc... i hope i make sense.
<FromGitter> <Blacksmoke16> See https://github.com/amberframework/granite/issues/331. Not actually sure where the `json_support` doc page went, but thats prob how you'd want to do it
<FromGitter> <vectorselector> yeah, i can't even figure out how to see the 'master' branch on github without cloning the repo and switching to it, doh... i don't see that json_support doc either... but anyway, there's essentially this on_to_json callback? ⏎ Anyway, I didn't understand the part about 'This would include a "members" property in the json output with a value of your members.' ⏎ Would this bring-in all Model.members
<FromGitter> ... under the "members" key?
<FromGitter> <Blacksmoke16> Granite models include https://crystal-lang.org/api/master/JSON/Serializable.html
<FromGitter> <Blacksmoke16> of which `on_to_json` is a thing that gets called after the ivars have been serialized, e.g. so you can add more data
<FromGitter> <Blacksmoke16> since relationships in Granite are methods, they aren't picked up by default via serializable, so you can use that `on_to_json` method to add them after the fact, which would set `members` JSON key, to the array of members you'd get if you did like `model.members`
<FromGitter> <Blacksmoke16> i.e. not *all* members, but only those related to that specific model instance
<FromGitter> <vectorselector> oh, that's exactly what i need.
<FromGitter> <vectorselector> thank you very much George
<FromGitter> <vectorselector> oh, this is great... it works perfectly.
<FromGitter> <Blacksmoke16> 👍