Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idiomatic way to filter on nested route? #55

Closed
neverfox opened this issue Apr 24, 2014 · 6 comments
Closed

Idiomatic way to filter on nested route? #55

neverfox opened this issue Apr 24, 2014 · 6 comments

Comments

@neverfox
Copy link
Contributor

I'm trying to figure out how to do filtering on child routes with emberfire since the adapter doesn't implement findQuery. I have the following:

  Advisor = DS.Model.extend
    accounts: hasMany "account", async: true
 Account = DS.Model.extend
    advisor: belongsTo "advisor", async: true
  App.Router.map ->
    @resource "advisor",
      path: "/advisor/:advisor_id", ->
        @resource "advisor.accounts",
          path: "/accounts", ->
            @route "new"
 AdvisorAccountsRoute = Ember.Route.extend #/advisor/:advisor_id/accounts
    model: ->
      # TODO: fetch only this advisor's accounts
      @store.findAll "account"

As you can see it currently fetches all the accounts, but what I want is only the accounts for the advisor in question. Am I supposed to pull all of the accounts into my controller and then filter there (setting the controller to also have the model for the advisor so that I can perform the filter)? That seems less than ideal, but I cannot see any other way. What I would be tempted to do in any other case would be:

 AdvisorAccountsRoute = Ember.Route.extend #/advisor/:advisor_id/accounts
    model: ->
      @store.filter "account", (account) ->
        account.get("advisor").then (advisor) =>
          Ember.isEqual advisor, @modelFor "advisor"

This seems like a common enough scenario that I'm hoping someone will be able to provide an example of the most efficient way to do this. Note that it's imperative that the solution guarantee async resolution of all the data from Firebase before the controller starts computing anything.

@neverfox neverfox changed the title Idiomatic way to filter? Idiomatic way to filter on nested route? Apr 24, 2014
@JFickel
Copy link

JFickel commented Apr 24, 2014

What about something like this for your advisor accounts route?

model: function() {
  this.modelFor("advisor").get("accounts").then(function(accounts) {
    return accounts
  }
}

@neverfox
Copy link
Contributor Author

@JFickel Ah! I'm coming from using fireplace, where I had tried that and it didn't work (because it doesn't return a PromiseModel) and so I forgot to try it with emberFire. I'll comfirm and close this it if it works.

@neverfox
Copy link
Contributor Author

I am curious though, for other reasons, is it something idiosyncratic about working with Firebase relationships that prevents or makes difficult implementing findQuery?

@aputinski
Copy link
Collaborator

@neverfox I'm working on implementing findQuery() now and it's definitely an interesting paradigm to integrate with Ember

@neverfox
Copy link
Contributor Author

@JFickel Yep, that works great.

@jakejuby
Copy link

@aputinski Would you mind pushing your branch for implementing findQuery()? I would like to check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants