ember.jsfirebasefirebase-realtime-databaseemberfire

How to query a relationship object using Emberfire?


I am creating a simple flash card app. The model is simple each user has many cars.

The problem is I would like to get cards which are created before a certain date (JS milliseconds).

model() {
    const session = this.get('session').content;
    return this.store.query('user', {orderBy: 'uid', equalTo: session.uid})
        .then((records) => {
            return records.get('firstObject');
        }).then((userData) => {
            return userData.get('cards');
        });
}

I can get all cards belong to a user use the snippet above, but how can I get cards only meet certain conditions? (For example, get cards which are created before certain date)


Solution

  • model() {
        const session = this.get('session').content;
        const now = Date.now('') + '';
        return this.store.query('user', {orderBy: 'uid', equalTo: session.uid})
            .then((records) => {
                return records.get('firstObject');
            }).then((userData) => {
                return userData.store.query(
                    'card',
                    {
                        orderBy: 'updatedAt',
                        endAt: 1481641085721
                    });
            });
    }
    

    I try to query again on the userData to meet my requirement.