2017-08-14 67 views
0

我正在使用Sailsjs v1.0.0-36。我想禁用模型人口。禁用風帆模型的自動填充v1.0

所以當我發送GET請求http://my-app/pets

[ 
    { 
    id: 1, 
    breed: 'Wolves', 
    type: 'Direwolf', 
    name: 'Ghost', 
    owner: 1, //user id 
    }, 
    { 
    id: 2, 
    breed: 'Wolves', 
    type: 'Direwolf', 
    name: 'Summer', 
    owner: 1, //user id 
    }, 
] 

,當我發送GET請求http://my-app/users

[ 
    { 
    id: 1 
    firstName: 'John', 
    lastName: 'Snow', 
    pets: [ //array of pets id 
     1, 
     2, 
    ] 
    } 
] 

User模型定義爲

// myApp/api/models/User.js 
 
// A user may have many pets 
 
module.exports = { 
 
    attributes: { 
 
    firstName: { 
 
     type: 'string' 
 
    }, 
 
    lastName: { 
 
     type: 'string' 
 
    }, 
 

 
    // Add a reference to Pets 
 
    pets: { 
 
     collection: 'pet', 
 
     via: 'owner' 
 
    } 
 
    } 
 
};

而且Pet模型定義爲

// myApp/api/models/Pet.js 
 
// A pet may only belong to a single user 
 
module.exports = { 
 
    attributes: { 
 
    breed: { 
 
     type: 'string' 
 
    }, 
 
    type: { 
 
     type: 'string' 
 
    }, 
 
    name: { 
 
     type: 'string' 
 
    }, 
 

 
    // Add a reference to User 
 
    owner: { 
 
     model: 'user' 
 
    } 
 
    } 
 
};

在帆v0.12.0,你可以做,在/config/blueprints.js通過設置

populate = false 

但這是帆v1.0過時,以下this從文檔我們可以通過重寫parseBlueprintOptions來實現,而this是該函數的默認實現。

我該如何重寫這個來達到所需的結果?

回答

0

據此commit sailjs 1.0開始再次支持這個選項。