Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to map mongo documents with subdocuments in symfony2
    primarykey
    data
    text
    <p>I'm trying to create symfony2 application which will access mongoDB collection with the following structure:</p> <pre><code>{ "_id": ObjectId("5239c1c0359bf908058a5071"), "param2": "test", "param3": { "subparam31": 0, "subparam32": 0, "subparam33": 0 }, "param4": 1 } </code></pre> <p>In symfony 2 I create a .yml, and php class. I correctly map only "_id", "param2" and "param4", but not "subparam31", "subparam32" and "subparam33" of "param3".</p> <p>I use next file structure for mapping:</p> <p>Params.mongodb.yml:</p> <pre><code>Acme\StoreBundle\Document\Params: db: test type: document fields: id: id: true param2: type: string param3: type: mixed subparam31: type: float subparam32: type: float subparam33: type: float param4: type: float </code></pre> <p>Params.php</p> <pre><code>&lt;?php namespace Acme\StoreBundle\Document; class Params { protected $param2; protected $param4; protected $param3; protected $subparam31; protected $subparam32; protected $subparam33; } ?&gt; </code></pre> <p>Where I'm wrong? How to get and set values of subparams?</p> <p>For accessing param2, param4 and id I use following code in controller which works:</p> <pre><code>$parameter = $this-&gt;get('doctrine_mongodb') -&gt;getRepository('AcmeStoreBundle:Params') -&gt;find($id); $parameter2 = $parameter-&gt;getParam2(); $parameter4 = $parameter-&gt;getParam4(); if (!$format) { throw $this-&gt;createNotFoundException('Not found parameter with id -&gt; '.$id); } return array( "parameter2" =&gt; $parameter2, "parameter4" =&gt; $parameter4 ); </code></pre> <p>I hope I was clear enough. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload