odm

Doctrine ODM returns proxy object for base class instead of sub-classed document

余生颓废 提交于 2020-01-24 21:50:09
问题 During my work on providing new functionality to my project, I decided to expand models. I decided to use base class, grouping common methods, with few sub-classes, all kept in a single collection. Base, abstract class: /** * @MongoDB\Document(repositoryClass="EntryRepository") * @MongoDB\MappedSuperclass * @MongoDB\InheritanceType("SINGLE_COLLECTION") * @MongoDB\DiscriminatorField(fieldName="type") * @MongoDB\DiscriminatorMap({"entry"="Application_Model_Entry", "image"="Application_Model

What is the difference between an ORM and an ODM?

Deadly 提交于 2019-12-29 10:04:11
问题 I am trying to figure out what the difference is between ORM and ODM, as far as I understand the concept, ORM (Object Relational Mapper) maps the relations between data, where as ODM (Object Document Mapper) deals with documents. Am I right in assuming that mySQL is an example of ORM and MongoDB is a example of ODM? As I am sure you can see, I am not too familiar with the theory of the concept. Could someone please clarify the differences between the two? 回答1: MySQL is an example of a

Doctrine ODM MongoDB EmbedOne Document not loaded

為{幸葍}努か 提交于 2019-12-24 10:23:57
问题 I need to store some data for our booking and thats include the customer data, which I want as embedded document within my booking document. With my current configuration all data are persisted in MongoDB, but when I load the booking document, there is no related customer object. Did I forget some configuration or something else? This is how my documents look like: The Booking-Document: <?php namespace AppBundle\Document; use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** * @MongoDB

Querying array elements with Mongo

…衆ロ難τιáo~ 提交于 2019-12-18 01:33:56
问题 How can I query the smoothies that have apple in them? (below is a collection with 3 documents) _id => 1 name => 'best smoothie' ingredients => Array ( [0] => apple [1] => raspberry [2] => orange [3] => banana ) _id => 2 name => 'summer smoothie' ingredients => Array ( [0] => lemon [1] => mint ) _id => 3 name => 'yogurt smoothie' ingredients => Array ( [0] => apple [1] => blueberry ) 回答1: If you simply run the below query MongoDB is smart enough to figure out what you're trying to do. {

convert javascript plain object into model class instance

你。 提交于 2019-12-12 09:34:23
问题 I need to implement small ODM like feature. I get plain javascript object from database, and I need to convert it into my model class instance. Let's assume model looks like: class Model{ constructor(){ this.a = '777'; ---- whole bunch of other things --- } print(){ console.log(this.a); } } So I need convert var a = {b:999, c:666} to instance of model and being able to call a.print() after, and when a.print() executed 777 should be placed in console. How to do that? 回答1: There have a simple

Lazy load between referenced documents on MongoDB with Doctrine ODM

与世无争的帅哥 提交于 2019-12-11 19:19:19
问题 Helo, firstly, please excuse my English, is not very good. I am migrating the data container of a Symfony2 application to MongoDB, before that it run with MySQL. I added the DoctrineMongoDBBundle and "almost everything" works perfectly. I have some references between documents in which I would like to keep the "lazy load" pattern offered by the Doctrine ORM. I have read the official documentation for Doctrine ODM, http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest

How do we create a Schema at runtime in Mongoose ODM?

给你一囗甜甜゛ 提交于 2019-12-06 15:02:45
问题 It's my understanding that Mongoose Schema's are defined at some point in the initiating stages of a Node app. These will obviously be hard coded, like so: var SomeSchema = new Schema({ some_string:String, some_number:Number }); If I'm creating a CMS whereby the administrator (via a pretty web GUI) could add their own models, with their own pre-defined types (sometimes custom types like e-mail) the app would need to create these Schema's on the fly. Sometimes adding to existing Schemas

convert javascript plain object into model class instance

不问归期 提交于 2019-12-05 01:56:04
I need to implement small ODM like feature. I get plain javascript object from database, and I need to convert it into my model class instance. Let's assume model looks like: class Model{ constructor(){ this.a = '777'; ---- whole bunch of other things --- } print(){ console.log(this.a); } } So I need convert var a = {b:999, c:666} to instance of model and being able to call a.print() after, and when a.print() executed 777 should be placed in console. How to do that? There have a simple method. Just assign the object to instance(this) class Model { constructor(obj){ Object.assign(this, obj) }

How do we create a Schema at runtime in Mongoose ODM?

回眸只為那壹抹淺笑 提交于 2019-12-04 19:30:03
It's my understanding that Mongoose Schema's are defined at some point in the initiating stages of a Node app. These will obviously be hard coded, like so: var SomeSchema = new Schema({ some_string:String, some_number:Number }); If I'm creating a CMS whereby the administrator (via a pretty web GUI) could add their own models, with their own pre-defined types (sometimes custom types like e-mail) the app would need to create these Schema's on the fly. Sometimes adding to existing Schemas (presumably using Mongoose's add() method, and sometimes creating new Schemas all-together. I've done some

Mongoid or MongoMapper? [closed]

ε祈祈猫儿з 提交于 2019-11-29 20:01:09
I have tried MongoMapper and it is feature complete (offering almost all AR functionality) but i was not very happy with the performance when using large datasets. Has anyone compared with Mongoid? Any performance gains ? Aynat I have used MongoMapper for awhile but decided to migrate to MongoId. The reason is hidden issues plus arrogance towards users. I had to jump through hoops to make MongoMapper work with Cucumber (succeeded in the end) and to put a couple of patches even the project was simple, but it's not the point. When I tried to submit a bug fix (due to incompatibility with