Fork me on GitHub

hey everyone, i am wondering if there is a way to build a query that uses the results from one part of the query as the parameters to the next part of the query. i'm doing this with remote queries. here's an example: [:learn/active (:learn/sections ACTIVE-ID)]


so :learn/active will fetch the active id from remote, then learn/sections will take that id as a param and call the remote again to get the sections?


@azzikid run the first query and in componentWillUpdate look for changes in the properties (see if your remote data has arrived), if yes, then either use om/update-query! or om/set-query! to trigger a new read with new query.


Was thinking if it would make sense if the parser had the ability to control the merge function, many remote queries merge differently in some of my apps, that {:value/:action :remote :merge} would sound nice, but the drawbacks could be worse than the benefits of this setup.


@hlolli that did it! thanks!


new issue i have is that i am getting the error: No queries exist for component path ... my root component query has [:app/learn (om/get-query Active) (om/get-query Sections)]. the error occurs when changing the params in the Sections component with update-query! after componentWillUpdate is called.


@azzikid if you used set-query! did you remember to merge all the existing queries you wanted to stay? this is bit like atomic reset!


i actually used update-query!


(om/update-query! this (fn [{:keys [query params] :as q}]
                             (assoc q :params new-params))


@hlolli that's how i updated the query in the Sections componentWillUpdate


doesn't look like the query parameter inside the following query ({:learn/sections [:learn/sections]} ?pouchq) is doing much, it's outside of the join and not a parameter. But these No queries exists errors are most of the time caused by inconsistency of the root component and a child component. So look trough the queries in the root component and if the methods in the parsers are correctly setup (ex if the data is normalized/vectorized or not)


I'm having trouble with a read method... I'm fetching a list of items with params to filter/limit the results. If I include both :remote and :value keys in the map I return, i get two remote requests. I'm not sure how to know whether I want to return the list from state or from remote...How do I know if params/resultset has changed?


If i change the search param, I end up in an infinite loop...remote call, merge, remote call, merge, remote call..


I can't just test to see if the key is in state, because it could be there but it can be the resultset from a previous query with different params...


My only idea is to update the params with some unique key every time i update the query...and then i can check if this matches the last one


Think that it might just be how I designed the components to update the params actually, entering into render loops


Yeah, resolved it with something like this

(componentDidUpdate [this prev-props prev-state]
    (when (and (not= prev-state (om/get-state this)) (= prev-props (om/props this)))


maybe i can redesign things to be more logical...


@azzikid I also had now for 15 minues a battle with No queries exist on path. And strangely by not passing properties into component C from B in A->B->C structure fixed it. Sometimes I feel like I don't know anything about


Hmm still stuck on it.


Are there any emergent resources on mastering read and mutation functions?


hey everyone, I just stumbled upon this article and I realized I can probably use this a lot (edited) is there “a good way/recommended way” to do this in om-next?


(reposted from #om-next )