script
Hi:
I am working on this library for querying, and I have this problem for preloading tables. My params are like this:
%{
"customer" => %{
"$binding" => :first,
"$include" => %{"users" => %{"$binding" => :last}}
},
"facilities" => %{
"$binding" => :first,
"$include" => %{"instance" => %{"$binding" => :last}}
},
"instances" => %{"$binding" => :first, "$include" => "facilities"}
}
I am successfully able to make joins for all of these thanks to @Eiji help. binding: :first means bind to the main table and binding_ :last bind to the last table. These params are dynamic and contain any number of nested includes.
The problem I am facing is preloading them dynamically. So far I am successful to build dynamic preloads from the above. I wrote a function that loop through the params and build a list like below
preload: [ {:instances, :facilities}, [customer: :users, facilities: :instance]]>
But as I go one more level deep like this:
%{
"customer" => %{
"$binding" => :first,
"$include" => %{"users" => %{"$binding" => :last, "$include" => %{"items" => %{"$binding" => :last}}}}
}
The preload will look like this
preload: [ {:instances, :facilities}, [customer: {:users, :items}, facilities: :instance]]>
And it’s not very maintainable and I even don’t know how to approach it.
Can anyone please suggest any workaround for this.
Is there any other approach I can take which is not this complex?
Thanks
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Eiji
@script Can you please share your code for collecting
preloadlist and howpreloadshould work for more levels deep? Also some people may not know what you said, so I would just like to your previous question.script
Thanks, @Eiji for providing the link to the question. Below is the code. It’s not optimized as your code looks
but it’s doing the work for now.
This code is looping through the params and if the
$includeis a map it will use a tuple to preload the nested table with the outer table else just the first table.The output is this:
If I add another
$includemap inside users as I showed above in my second example. This function should produce preload like this:And if there is another nested include inside
itemsthe list looks like this:Eiji
Here is my first version:
Please let me know if it works as expected for you in all cases.
script
Thanks @Eiji. I will let you know.
script
Hi @Eiji. so, I give it a try with below params.
The output it produced is this:
The last line has correct output but it’s returning all other values before the final result. I think it’s reducing over the params and instead if returning the final output returns all the value it’s reducing over.
Eiji
@script Sorry, I completely don’t understand.
For me
Example.sample(data)returns[]for such input. I have no idea how it become like that. Looks like you did not gave a correct input here.This is not even 1 list. How 1 call could turn into multiple results? Here looks like you pass few different inputs.
I have no information what happen on your side. Please send me all cases with their expected results. Something like in
TDD, so if all tests would pass then implementation is correct.If you have a public repo simply add tests like:
and I will just make a PR for that.
script
Sorry, @Eiji. you are right. it is an issue on my end. I am debugging it. I will let you know.
Thanks for your quick insight.
script
@Eiji Thanks. It works perfectly as always.
script
@Eiji sorry Just his one case I forgot to mention if there is a
list.The prelod list looks like this:
Eiji
@script Here we go:
Just one extra function clausule. It’s why I love writing configurable and easy to maintain code!