I am using Symfony 2.1 and Doctrine - MongoDBBundle.
I have three documents. The first is a company, which I call "Institution". The second are contacts inside the institution, and the third are the talks the user had with the contact.
Contact and Exchange are embedded into Institution, which is true in real world. This is not a problem.
But a Contact is referenced into an Exchange document. This seem to be more complicated with doctrine2...
At first, I would like to build a form which suggest (in a "option" field, which is Native Choices field or Document field in Symfony 2.1) only the contact embedded in the Institution which is currently "edited".
How to do this ?
I tryed to used data transformers. But this lead to another problem: if I have the Contact object, how can I retrieve the parent "Institution" object ?
Is this possible with a MongoDB native query ? Or with query builder ?
This is my YAML mapping:
For Institution:
SOFFT\ContactBundle\Document\Institution:
type: document
fields:
id:
id: true
type: id
# ...
embedMany:
contacts:
targetDocument: Contact
exchange:
targetDocument: Exchange
for Contact:
SOFFT\ContactBundle\Document\Contact:
type: embeddedDocument
fields:
id:
id: true
#...
for Exchange:
SOFFT\ContactBundle\Document\Exchange:
type: embeddedDocument
fields:
id:
id: true
#...
referenceOne:
contact:
targetDocument: Contact