2017-11-10 2 views
0

Sequelize v3.30.4를 사용하고 있습니다. 중첩 된 JSONB 객체의 필드에 의한 질의를 쿼리 할 수 ​​없습니다. 사용자의이 열은 payload이고 필드는 priority입니다. 나는 postgres 방언을 사용하고있다. 가능한 경우 원시 쿼리없이 SQL 원시 쿼리를 사용하지 않고이 작업을 수행하는 방법에 대해 궁금합니다. 나는 이러한 모든 주석 방법을 시도하고 당신이 볼 수있는 다른이 규칙에 따라 순서를 설정 걸려 :Sequelize : JSONB 개체의 필드로 주문 쿼리

function getUsers (id, req, res) { 
    const sequelize = req.app.context.sequelize; 
    const User = sequelize.model('user'); 
    const Post = sequelize.model('post'); 
    const Tag = sequelize.model('tag'); 

    return User.findOne({ 
    where: { id }, 
    include: [ 
    Post, 
     Tag 
    ], 
    order: [ 
     // ['payload.priority'], 
     // [sequelize.json('users.payload.priority', 'ASC')], 
     // [User.payload.priority], 
     // [User.payload, 'priority', 'ASC'], 
     // [User, 'payload', 'priority', 'ASC'], 
     // ['payload', 'priority', 'ASC'], 
     // ['payload', 'priority'], 
     [Post, 'rank'], 
     [Tag, 'rank'] 
    ] 
    ... 
}) 

답변

0

그냥 내가 sequelize을 사용하고

function getUsers (id, req, res) { 
    const sequelize = req.app.context.sequelize; 
    const User = sequelize.model('user'); 
    const Post = sequelize.model('post'); 
    const Tag = sequelize.model('tag'); 

    return User.findOne({ 
    where: { id }, 
    include: [ 
    Post, 
     Tag 
    ], 
    order: [ 
     ['payload.priority','asc'] 
    ] 
}) 

다음과 같은 방법으로 사용할 수 있습니다 버전 4.33.0과 나를 이를 위해 잘 작동 코딩 행복 https://github.com/sequelize/sequelize/pull/7565/files/b5d77ecedbe96d47d053cb9f11e10cdf0f84d0ae

어떤 쿼리의 경우에 알려 병합 된 요청에 대한 링크 :

입니다