node.js - Adding limit to sequelize findAll destroys the query? -


i'm trying return group of models, paginated using limit , offset, including grouped count of model's favorites. trivial thing attempt.

here's basic query setup sequelize:

var perpage = 12; var page = 1;  return model.findall({      group: [ 'model.id', 'favorites.id' ],     attributes: [         '*',         [ sequelize.fn('count', sequelize.col('favorites.id')), 'favorites_count' ]     ],     include: [         { attributes: [], model: favorite },     ],     offset: perpage * page 

this generates (fairly) expected query:

select          "model"."id",                 "model".*,                 count("favorites"."id") "favorites_count",                 "favorites"."id"        "favorites.id"            "model"                 "model" left outer join "favorite"              "favorites" on              "model"."id" = "favorites"."model_id" group        "model"."id",                 "favorites"."id" offset 12; 

ignoring fact quotes tables, , selects favorites.id (forcing me add group clause), , has randomly aliased things exact name or nonsensical name "favorites.id" (all undesired), seems have worked. let's complete pagination , add limit query:

... offset: perpage * page limit: perpage 

it generates query:

select "model".*,     "favorites"."id" "favorites.id"   (select "model"."id",             "model".*,             count("favorites"."id") "favorites_count"           "model" "model"         group  "model"."id",                 "favorites"."id"         limit  12 offset 12) "model"     left outer join "favorite" "favorites"                     on "model"."id" = "favorites"."model"; 

in baffling behavior, has generated inner query , applied limit that, aliased "model".

as sanity check looked in docs findall, docs do not seem think command exists.

i suspect doing wrong, can't figure out is. behavior quite bizzarre, , i'm hoping sleep deprivation cause of confusion.

i'm using version 2.0.6

you can use limit , offset in findandcount example

hope helps


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -