Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4826

Automatic fetching data with name-convention

$
0
0

@Panx36 wrote:

I am building a smarthone app to learn ember. A user got households which got rooms and so on. When I click on a user I want to show his households and after that I want to click on a household to show all rooms in that household. My Router.js looks like this:

Router.map(function() {
  this.route('about');

  this.route('users', function() { //Lists all the users, URL looks like /users
    this.route('single', { path: '/:user_id' }, function() { //Actually i did not use this route
      this.route('households', function() { ;// Shows all households a user with user_id has, URL looks like /users/123/households
        this.route('single', { path: '/:household_id' }, function() { // Shows a single household, URL looks like /users/123/households/456
          this.route('rooms', function() { // Shows all rooms a household with household_id has, URL looks like /users/123/households/456/rooms
            this.route('single', { path: '/:room_id' }, function() {
              this.route('devices', function() {});
            });
          });
        });
      });
    });
  });
});

If I call {{#link-to ‘users.single.households’ user.id}} the route ‘households’ is called. This is fine. In this route i need access to the user.id. This is working with the following statement in the household-route model hook.

var parentModel = this.modelFor(‘users.single’);

complete route:

import Route from '@ember/routing/route';

export default Route.extend({
    model(){
        console.log('household route');
        var parentModel = this.modelFor('users.single');

   return Ember.RSVP.hash({

            user: parentModel,

            household: this.get('store').findAll('household').then(results => results.filter((site) => {
            return site.get('member').filter(x => x == parentModel.id).length > 0;
       })),
          });
    }
});

Now I am stuck with adding new objects to the store cause of the name-convention or automatic data fetch. My child-route users.single is never called. In my understanding this is because of the naming convention user_id. For listing my data from the mirage server this woks fine. But if I want to push a new object to the store, the automatic request for a user_id did not find my new object which is only stored in the store and not stored in the database on my mirage-server. Is there any option to override the default automatic fetch? I want to try to use peekRecord instead of findRecord.

OR

Is it possible to use an other param name like ‘useridnumber’? But when i am doing this:

this.route(‘single’, { path: ‘/:useridnumber’ }, function() {

my route user.single is even never called.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles