Returning events that have bookings inside


#1

Hei guys!

I’m having a bad time! I need return in my route only events with bookings inside, and i’m trying like this:

  setupController(controller, model) {
    controller.set('events', this.store.findAll('event').then((events) => {
      return events.filter((event) => {
        let bookings = this.store.query('booking', {
          'relationships.event.data.id': event.id
        });

        if (bookings.get('length')) {
          return event;
        }
      });
    }));
  }

The problem is: The request is async, so isn’t returning anything.

How could i solve this problem?

Thanks guys!


#2

Try moving that piece of code out of setupController() and into model().

Then access all the events by the model instead of the controller property ‘events’