我正在使用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是該函數的默認實現。
我該如何重寫這個來達到所需的結果?