流星ORM多态& Mongo文件

时间:2012-09-22 10:49:39

标签: meteor

我听说有forthcoming Meteor ORM

我有兴趣以与Polymorphic Models for Django类似的方式使用它。

首先,类似于Mongo Documents提供的django-polymorphic的多态表示,其次,如何使用Meteor Collections?

1 个答案:

答案 0 :(得分:0)

在您撰写问题时,这可能不可行,但现在可以通过在transform的实例化或new Mongo.Collection或{MyCollection.find实例化时使用findOne选项来实现{1}}。鉴于您想要进行多态模型,您很可能在查询期间使用transform选项。

查看以下文档中的transform选项:

http://docs.meteor.com/#/full/mongo_collection

http://docs.meteor.com/#/full/find

http://docs.meteor.com/#/full/findone

以下是一个例子:

// Your MongoDB collections
Resources = new Mongo.Collection('resource');

// Define your model
function ProductModel (resource) { /* Model Stuff */ }

// As you fetch your data, instantiate the models using the `transform` option
var product = Resources.findOne(myFilter, {
  transform: function (document) {
    return new ProductModel(document);
  }
});

有很多软件包可以让你像AstronomyGraviton一样立即获得模型。

相关问题