YAML mapping doc User
User
slug:
unique:
order: desc
type: string
roles:
reference: true
type: many
targetDocument: Role
cascade: all
Role
Role:
type: document
collection: Role
fields:
name:
id: true
strategy: none
type: string
Now adding new role to that user updating a blank object without storing any DB ref and no error. $user->getRoles()
returns array of Role object. As reference are by default stored as DbRef, i was expecting the entry would be a DbRef. But it is not in this case.
$updateApprove = $this->persistantManager->createQueryBuilder('User')
->field('slug')
->equals($user->getSlug())
->findAndUpdate()
->returnNew()
->field('roles');
$updateApprove->set($user->getRoles());
$updatedUser = $updateApprove->getQuery()
->execute();
Data in db after for roles executing field is showing as
"roles" : [
{},
{}
]