Meteor ORM Polymorphic and Mongo Papers

I heard the upcoming ORM Meteor there .

I am interested in working with it similarly to Polymorphic models for Django .

Firstly, a polymorphic view like django-polymorphic is available with Mongo Documents, and secondly, how can this be done with Meteor Collections?

+4
source share
1 answer

While you wrote your question, this is probably not feasible, but now it is possible using the transform parameter either when creating new Mongo.Collection , or when executing MyCollection.find or findOne . Given that you want to use polymorphic models, most likely you will use the transform parameter during queries.

Check out the transform parameter in the following documentation:

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

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

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

Here is an example:

 // 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); } }); 

There are tons of packages that give you the power of models from the start, like Astronomy and Graviton .

0
source

Source: https://habr.com/ru/post/1435652/


All Articles