在sequelize中是否可以使用嵌套的预先加载来对嵌套请求进行分页?

时间:2016-03-19 13:42:57

标签: node.js sequelize.js

我正在使用Nested eager loading功能,这是续集的例子:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Google Cloud Dataflow Java Examples - All manual_build
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- build-helper-maven-plugin:1.10:add-source (add-java8-main-source) @ google-cloud-dataflow-java-examples-all ---
[INFO] Source directory: /home/gaurav_bareja/pipeline/DataflowJavaSDK-examples/src/main/java8 added.
[INFO] 
[INFO] --- build-helper-maven-plugin:1.10:add-test-source (add-java8-test-source) @ google-cloud-dataflow-java-exam
ples-all ---
[INFO] Test Source directory: /home/gaurav_bareja/pipeline/DataflowJavaSDK-examples/src/test/java8 added.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ google-cloud-dataflow-java-examples-all ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/gaurav_bareja/pipeline/DataflowJavaSDK-examples/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ google-cloud-dataflow-java-examples-all ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (java8-compile) @ google-cloud-dataflow-java-examples-all ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] >>> exec-maven-plugin:1.1:java (default-cli) > validate @ google-cloud-dataflow-java-examples-all >>>
[INFO] 
[INFO] <<< exec-maven-plugin:1.1:java (default-cli) < validate @ google-cloud-dataflow-java-examples-all <<<
[INFO] 
[INFO] --- exec-maven-plugin:1.1:java (default-cli) @ google-cloud-dataflow-java-examples-all ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.496 s
[INFO] Finished at: 2016-03-19T13:23:56+00:00
[INFO] Final Memory: 15M/56M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1:java (default-cli) on project google-cloud-d
ataflow-java-examples-all: An exception occured while executing the Java class. com.google.cloud.dataflow.examples.
complete.StreamingWordCount.java -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecution

想象一下,您想要执行User.findAll({ include: [{ model: Tool, as: 'Instruments', include: [{ model: Teacher, where: { school: "Woodstock Music School" }, required: false }] }] }).then(function(users) { /* ... */ }) '摘要'并希望包含endpoint,但只包含前三个结果

只能使用嵌套的预先加载?

Sequelize提供了实现此目的的方法吗?

2 个答案:

答案 0 :(得分:2)

在尝试了很多事情之后,我得出的结论是它无法直接做到。

答案 1 :(得分:1)

您可以使用教师模型的限制和偏移量

 User.findAll({
    include: [{
            model: Tool,
            as: 'Instruments',
            include: [{
                    model: Teacher,
                    where: {
                        school: "Woodstock Music School"
                    },
                      limit: 3,
                    required: false
                }
            ]
        }
    ]
}).then(function (users) {
    /* ... */
})