SailsJS Blueprints собирается с трудом - PullRequest
0 голосов
/ 18 мая 2018

Я работал над приложением, использующим SailsJS v0.12.Приложение работает как положено.Но для некоторых модулей имело смысл перейти на v1.0, потому что он предлагал некоторые замечательные функции, а веб-сайт подразумевал (или казался таковым), что процесс обновления был простым.

Это не имело место,После дня утомительного рефакторинга я преуспел в создании существующего кода и начал работать над новыми модулями.Проблема, на которой нужно было сосредоточиться, началась здесь.

Я запустил функции, как делал это ранее в POSTman , и перестал получать ответ.Чтобы проверить отдельные модели, я попытался использовать чертежи.Поскольку никаких структурных изменений не было внесено ни в одну из моделей, это должно было сработать.Но я не смог получить ответ в POST;GET все еще работал.Я вышел из системы для перерыва, а затем сделал GET-запрос к модели с некоторыми ассоциациями (прекрасно работал раньше).

Я получил этот ответ

UsageError: Invalid populate (s),Детали: Не удалось заполнить customer из-за неоднозначного использования.Это единственное («модельное») объединение, которое означает, что оно никогда не ссылается на более чем одну связанную запись.Таким образом, передача подкритериев (т. Е. В качестве второго аргумента .populate()) не поддерживается для этой ассоциации, так как обычно она не имеет никакого смысла.Но вот в чем проблема - похоже, что-то вроде подкритерия (или чего-то) было предоставлено !(Обратите внимание, что подкритерии, состоящие ТОЛЬКО из omit или select, являются особым случаем, который имеет смысл. Это использование будет поддерживаться в будущей версии Waterline.)

Вот чтобыло передано в: {limit: 30}

Полный ответ JSON:

{
    "stack": "UsageError: Invalid populate(s).\nDetails:\n  Could not populate `customer` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ limit: 30 }\n\n    at findRecords (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\blueprints\\actions\\find.js:40:21)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at alwaysAllow (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\policies\\index.js:224:11)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at module.exports (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\cors\\clear-headers.js:14:3)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at sails.router.bind._middlewareType (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\csrf\\index.js:148:11)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:167:11)\n    at _addResViewMethod (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\hooks\\views\\res.view.js:372:3)\n    at routeTargetFnWrapper (D:\\Dev\\NodeJS\\zingr\\node_modules\\sails\\lib\\router\\bind.js:181:5)\n    at callbacks (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:164:37)\n    at param (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:138:11)\n    at pass (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:145:5)\n    at nextRoute (D:\\Dev\\NodeJS\\zingr\\node_modules\\express\\lib\\router\\index.js:100:7)",
    "message": "Invalid populate(s).\nDetails:\n  Could not populate `customer` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ limit: 30 }\n",
    "name": "UsageError",
    "code": "E_INVALID_POPULATES",
    "details": "Could not populate `customer` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ limit: 30 }"
}

Запутанный аспект заключается в том, что это происходит только локально.Чертежи отлично работают, как и ожидалось, при развертывании (тот же код, с двойной проверкой), размещенном на Zeit.co.Я проверил это достаточно раз, чтобы понять, что это не ошибка в моих моделях.Тем не менее, вот модели - Bill и Customer:

models\Bill.js

module.exports = {

    primaryKey:'id',
    attributes: {
        createdAt: { type: 'number', autoCreatedAt: true, },
        updatedAt: { type: 'number', autoUpdatedAt: true, },

        id:{
            type:'string',
            required:true
        },
        bill_number:{
            type:'string'
        },
        admin_id:{
            type:'string'
        },
        channel:{
            type:'string'
        },
        amount:{
            type:'number'
        },
        discount:{
            type:'number',
            defaultsTo:0
        },
        order_date:{
            type: 'number'
        },
        status:{
            type:'string',
            isIn:['generated', 'settled', 'canceled'],
            defaultsTo:'generated'
        },
        type:{
            type:'string',
            isIn:['dine-in', 'take-away', 'delivery', 'logistics-delivery'],
            required:true
        },
        logisticsPartner:{
            type:'string',
            defaultsTo:'phone'
        },

        //association
        customer:{
            model:'customer'
        },

        store:{
            model:'store'
        },
        orderContents:{
            collection:'billmapping',
            via:'bill'
        },
        transactions:{
            collection:'transaction',
            via:'bill'
        }
    }

};

models\Customer.js

module.exports = {

    attributes: {
        createdAt: { type: 'number', autoCreatedAt: true, },
        updatedAt: { type: 'number', autoUpdatedAt: true, },

        id: { type: 'number', autoIncrement: true}, // <-- for SQL databases
        name:{
            type:'string'
        },
        number:{
            type:'string',
            unique:true
        },
        email:{
            type:'string',
            unique:true
        },
        age:{
            type:'number'
        }
    }
};

Из-за этой проблемы я выдернул свои волосы в течение 8 часов.Кто-нибудь может пролить свет или поделиться некоторыми предложениями?

Заранее спасибо.

...