Keystonejs - 查询关系中的项目

时间:2016-09-09 14:40:21

标签: node.js mongodb express mongoose keystonejs

我想编写一个查询来过滤在其上设置关系的内容。

Laptopy.js

 var keystone = require('keystone');
    var Types = keystone.Field.Types;

    var Laptop = new keystone.List('Laptop', {
       map: { name: 'nazwa' },
       autokey: { path: 'slug', from: 'nazwa', unique: true },
    });

    Laptop.add({
       nazwa:{type: String, required: true},
       grafika:{type: Types.Relationship, ref: 'KartaGraficzna'}

    });
    Laptop.register();

KartaGraficzna.js

var keystone = require('keystone');
var Types = keystone.Field.Types;

var KartaGraficzna = new keystone.List('KartaGraficzna', {
   map: { name: 'nazwa' },
   autokey: { path: 'slug', from: 'nazwa', unique: true },
});

KartaGraficzna.add({
   nazwa:{type: String, required: true},
   producent:{type: Types.Select, options: 'nVidia, AMD, Intel'},
});

KartaGraficzna.relationship({ ref: 'Laptop', path: 'grafika' });
KartaGraficzna.register();

QUERY

var Laptop = keystone.list('laptops');
Laptop.model.find()
   .populate('grafika')
   .where('grafika.nazwa', 'GTX980')
   .exec(function (err, laptop) {
      locals.data.laptopy = laptop;
      next(err);
   });

我知道这个查询是错误的,这不是那样的。 谁能告诉我怎么做? 我将非常感谢你的帮助

1 个答案:

答案 0 :(得分:0)

非常不清楚问题陈述。=> 过滤设置了关系的内容。

我应该从中了解什么。当你提出一些矛盾的代码示例时也是如此。 ?

任何方式,如果我按单词overflow-y: auto; 我认为您不希望看到那些设置了grafika的笔记本电脑

所以我的答案是,只需与null比较。

filter the content that has relationships set