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

Multiple find with promise #29

Open
krisnamargono opened this issue Dec 27, 2016 · 0 comments
Open

Multiple find with promise #29

krisnamargono opened this issue Dec 27, 2016 · 0 comments

Comments

@krisnamargono
Copy link

Hello, is it possible to query twice and then save it into redis? I kinda confused on how to explain it. So here is my example code.

var cacheObj = models.cacher(models.sequelize, models.rc)
                .model('model1')
                .ttl(60);

            var allModel1Data = [];

            cacheObj.findAll({}).then(function(model1) {
                var allModel1Data = JSON.parse(JSON.stringify(model1));

                return models.Model2.findAll({})
            }).then(function(model2) {
                for(var i = 0; i < allModel1Data.length; i++) {
                    allModel1Data[i].Model2Array = [];

                    for(var j = 0; j < model2.length; j++) {
                        if(model2[j].Model1Id == allModel1Data[i].Id) {
                            allModel1Data[i].Model2Array.push(model2[j]);
                        }
                    }
                }

                return res.json({
                    success: true,
                    model1: allModel1Data
                })
            })

In the 'allModel1Data', it should be containing all the data combined from Model1 and Model2. But instead of that, it only returns [].
Am I wrong? Thanks for your help!

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

1 participant