1

I know how to store a simple Product Object in mongodb using symfony2:

This YAML file :

Acme\StoreBundle\Document\Product:
    fields:
        id:
            id:  true
        name:
            type: string
        price:
            type: float

Will produce this collection :

{ 
"_id" : ObjectId("..."), 
"name" : "...", 
"price" : "..." 
}

But now, I would like to know how to write something generating a structure like that :

{ 
"_id" : ObjectId("..."), 
"name" : "...", 
"price" : 
   { 
     "before" : "...", 
     "after" : "..." 
   }
}

Any idea or documentation link ?

1
  • 1
    +1 to compensate random downvote Commented Apr 12, 2013 at 9:42

1 Answer 1

3

You can use an embed document. http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/tutorials/getting-started.html

Acme\StoreBundle\Document\Product:
    fields:
        id:
            id:  true
        name:
            type: string
        referenceOne:
            price:
               targetDocument: Acme\StoreBundle\Documents\price
               cascade: all

Acme\StoreBundle\Documents\price:
    fields:
        before:
            type: float
        after:
            type: float


Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.