2015-02-04 2 views
4

1 대 다 관계의 두 모델입니다.Sails js가 자동으로 연관을 채 웁니까?

비디오 :

module.exports = { 
    attributes: { 
    ... (some attributes) 
    createdBy:{ 
     model: "user" 
    } 
    } 
}; 

사용자

module.exports = { 
    attributes: { 
     ... (some attributes) 
    videos:{ 
     collection: "video", 
     via: "createdBy" 
    }, 
    } 
}; 

내가 돛에 데이터를 요청하는 blueprints.js을 사용하고 있습니다. 올바르게 이해했다면, 내가 껐던 config/blueprints.js (populate : ture)에서 자동 채우기를 켜거나 끌 수 있습니다. 내가 예를 들어 GET /video/1를 요청할 때, 그것은 다음과 같은 나에게 인구 데이터를했다 : 나는 그것이 사용자의 아이디와 있어야하는데 생각

{ 
    "createdBy": { 
    "user_type": 3, 
    "id": 5, 
    "createdAt": "2015-01-21T03:36:04.832Z", 
    "updatedAt": "2015-02-03T04:35:02.671Z" 
    }, 
    "title": "test video", 
    "url": "http://localhost", 
    "description": "testing submission", 
    "view": 102, 
    "id": 5, 
    "createdAt": "2015-02-03T01:16:20.640Z", 
    "updatedAt": "2015-02-03T04:34:26.726Z" 
} 

createdBy 필드를. blueprints.js에서 자동 채우기가 해제 되어도 예상되는 동작입니까?

+0

'생산'모드로 실행하면 같은 방법으로 유지됩니까? – r0hitsharma

+0

아직 프로덕션으로 테스트하지 않았지만 아직 개발중인 프로세스 – REALFREE

+0

을 사용하고 있습니까? 비디오 테이블에서 DB 쿼리를 실행하여 정확하게 저장된 내용을 확인해 보셨습니까? –

답변

2

config/blueprints.js를 사용하여 구성 할 수 있습니다. 단지 당신이해야 할 일은 "채우기"를 찾아서 주석을 제거하고 거짓으로 설정하는 것입니다.

/** 
* Blueprint API Configuration 
* (sails.config.blueprints) 
* 
* These settings are for the global configuration of blueprint routes and 
* request options (which impact the behavior of blueprint actions). 
* 
* You may also override any of these settings on a per-controller basis 
* by defining a '_config' key in your controller definition, and assigning it 
* a configuration object with overrides for the settings in this file. 
* A lot of the configuration options below affect so-called "CRUD methods", 
* or your controllers' `find`, `create`, `update`, and `destroy` actions. 
* 
* It's important to realize that, even if you haven't defined these yourself, as long as 
* a model exists with the same name as the controller, Sails will respond with built-in CRUD 
* logic in the form of a JSON API, including support for sort, pagination, and filtering. 
* 
* For more information on the blueprint API, check out: 
* http://sailsjs.org/#!/documentation/reference/blueprint-api 
* 
* For more information on the settings in this file, see: 
* http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.blueprints.html 
* 
*/ 

module.exports.blueprints = { 

    /*************************************************************************** 
    *                   * 
    * Action routes speed up the backend development workflow by    * 
    * eliminating the need to manually bind routes. When enabled, GET, POST, * 
    * PUT, and DELETE routes will be generated for every one of a controller's * 
    * actions.                 * 
    *                   * 
    * If an `index` action exists, additional naked routes will be created for * 
    * it. Finally, all `actions` blueprints support an optional path   * 
    * parameter, `id`, for convenience.          * 
    *                   * 
    * `actions` are enabled by default, and can be OK for production--   * 
    * however, if you'd like to continue to use controller/action autorouting * 
    * in a production deployment, you must take great care not to    * 
    * inadvertently expose unsafe/unintentional controller logic to GET  * 
    * requests.                * 
    *                   * 
    ***************************************************************************/ 

    // actions: true, 

    /*************************************************************************** 
    *                   * 
    * RESTful routes (`sails.config.blueprints.rest`)       * 
    *                   * 
    * REST blueprints are the automatically generated routes Sails uses to  * 
    * expose a conventional REST API on top of a controller's `find`,   * 
    * `create`, `update`, and `destroy` actions.        * 
    *                   * 
    * For example, a BoatController with `rest` enabled generates the   * 
    * following routes:              * 
    * :::::::::::::::::::::::::::::::::::::::::::::::::::::::     * 
    * GET /boat -> BoatController.find          * 
    * GET /boat/:id -> BoatController.findOne         * 
    * POST /boat -> BoatController.create          * 
    * PUT /boat/:id -> BoatController.update         * 
    * DELETE /boat/:id -> BoatController.destroy        * 
    *                   * 
    * `rest` blueprint routes are enabled by default, and are suitable for use * 
    * in a production scenario, as long you take standard security precautions * 
    * (combine w/ policies, etc.)            * 
    *                   * 
    ***************************************************************************/ 

    // rest: true, 

    /*************************************************************************** 
    *                   * 
    * Shortcut routes are simple helpers to provide access to a    * 
    * controller's CRUD methods from your browser's URL bar. When enabled,  * 
    * GET, POST, PUT, and DELETE routes will be generated for the    * 
    * controller's`find`, `create`, `update`, and `destroy` actions.   * 
    *                   * 
    * `shortcuts` are enabled by default, but should be disabled in   * 
    * production.                * 
    *                   * 
    ***************************************************************************/ 

    // shortcuts: true, 

    /*************************************************************************** 
    *                   * 
    * An optional mount path for all blueprint routes on a controller,   * 
    * including `rest`, `actions`, and `shortcuts`. This allows you to take * 
    * advantage of blueprint routing, even if you need to namespace your API * 
    * methods.                 * 
    *                   * 
    * (NOTE: This only applies to blueprint autoroutes, not manual routes from * 
    * `sails.config.routes`)             * 
    *                   * 
    ***************************************************************************/ 

    // prefix: '', 

    /*************************************************************************** 
    *                   * 
    * An optional mount path for all REST blueprint routes on a controller. * 
    * And it do not include `actions` and `shortcuts` routes.     * 
    * This allows you to take advantage of REST blueprint routing,    * 
    * even if you need to namespace your RESTful API methods     * 
    *                   * 
    ***************************************************************************/ 

    // restPrefix: '', 

    /*************************************************************************** 
    *                   * 
    * Whether to pluralize controller names in blueprint routes.    * 
    *                   * 
    * (NOTE: This only applies to blueprint autoroutes, not manual routes from * 
    * `sails.config.routes`)             * 
    *                   * 
    * For example, REST blueprints for `FooController` with `pluralize`  * 
    * enabled:                 * 
    * GET /foos/:id?               * 
    * POST /foos                * 
    * PUT /foos/:id?               * 
    * DELETE /foos/:id?              * 
    *                   * 
    ***************************************************************************/ 

    // pluralize: false, 

    /*************************************************************************** 
    *                   * 
    * Whether the blueprint controllers should populate model fetches with  * 
    * data from other models which are linked by associations     * 
    *                   * 
    * If you have a lot of data in one-to-many associations, leaving this on * 
    * may result in very heavy api calls          * 
    *                   * 
    ***************************************************************************/ 

    populate: false, 

    /**************************************************************************** 
    *                   * 
    * Whether to run Model.watch() in the find and findOne blueprint actions. * 
    * Can be overridden on a per-model basis.         * 
    *                   * 
    ****************************************************************************/ 

    // autoWatch: true, 

    /**************************************************************************** 
    *                   * 
    * The default number of records to show in the response from a "find"  * 
    * action. Doubles as the default size of populated arrays if populate is * 
    * true.                  * 
    *                   * 
    ****************************************************************************/ 

    // defaultLimit: 30 

}; 
관련 문제