根据关联查找,但在结果中不包含结果中的关联
总之,我想使用include: [{ model, where }]
方法在表格中find某个东西,但实际上并不包含我所包含的模型。
我有两个模型,一个一对多的关联, Part
和Set
。 我发现属于Set
s的Part
s是基于Set
的slug
。 喜欢这个:
yield Part.findAll({ where: { slug: 'my-part' }, include : [{ model: Set, where: { slug: 'my-set' } }]...
这给了我一个像这样的数组:
[ { is: 1, slug: 'my-part', body: 'this is my nice part', Set: { slug: 'my-set', body: 'what a set', id: 1 } } ]
我只想得到这样的结果:
[ { is: 1, slug: 'my-part', body: 'this is my nice part' } ]
试试设置attributes: []
上的include:
yield Part.findAll({ where: { slug: 'my-part' }, include : [{ attributes: [], model: Set, where: { slug: 'my-set' } }]...