topfullstack / nestjs-mongoose-crud

Nest.js crud module for mongoose models without `nestjsx/crud`

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

populate这个属性无效,不能带出分类的数据

BeginsDuang opened this issue · comments

//controller.ts
 routes: {
    find: {
      populate:'CategorySchema',
      decorators: [
        UseGuards(AuthGuard('jwt')),
        ApiBearerAuth(),
        ApiOperation({ summary: '商品列表' }),
      ],
    }
}
//model.ts
@Prop({ ref: 'CategorySchema' })
@ApiProperty({ description: '分类' ,example: { _id: 'xxxxxxx' },})
category: Ref<CategorySchema>

看接口是这样设定的,在swagger里查询里直接输入
{"populate":"CategorySchema"}
也查显示不出来分类数据,还是ID

//swagger Response body
{
  "total": 2,
  "data": [
    {
      "_id": "5efb4c9b26102f26485897e0",
      "name": "土司",
      "price": "12",
      "category": "5ef72c8e5cc2e944e4384b89",
      "expirationDate": "2020-07-03",
      "costPrice": "5",
      "units": "",
      "pcs": "100",
      "createdAt": "2020-06-30T14:30:51.944Z",
      "updatedAt": "2020-06-30T14:30:51.944Z",
      "__v": 0
    },
    {
      "_id": "5efb4ce826102f26485897e1",
      "name": "水果船",
      "price": "20",
      "category": "5ef72c8e5cc2e944e4384b89",
      "expirationDate": "2020-07-02",
      "costPrice": "10",
      "units": "",
      "pcs": "12",
      "createdAt": "2020-06-30T14:32:08.710Z",
      "updatedAt": "2020-06-30T14:32:08.710Z",
      "__v": 0
    }
  ],
  "lastPage": 1,
  "page": 1
}

所有nestjs和mongodb相关的包都是最新版本

找到原因了,写错了,把模型写这个属性上了,应该是天关联的字段名称