Discussion:
[doctrine-user] Trouble getting started with the ODM: can't retrieve by id
Rohit Sodhia
2017-11-01 15:16:47 UTC
Permalink
I'm trying out the Doctrine ODM (and ORM) for the first time. I've created
a simple model for one of my collections:

<?php

namespace App\Models;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document */
class System
{
/** @ODM\Id(strategy="NONE", type="string") */
private $id;

/** @ODM\Field(type="string") */
private $name;

/** @ODM\Field(type="string") */
private $sortName;

/** @ODM\Field(type="hash") */
private $publisher;

/** @ODM\Field(type="collection") */
private $genres = array();

/** @ODM\Field(type="boolean") */
private $hasCharSheet;

/** @ODM\Field(type="int") */
private $lfg;

/** @ODM\Field(type="boolean") */
private $enabled;

public function setId(string $id)
{
$this->id = $id;
}
}

Then I tried a simple:

var_dump($this->doctrineODM->find('App\Models\System', 'afmbe'));

from which I simply got back a null. Based on everything I've ready (and
honestly, I don't like the Doctrine documentation much at all), the id
should map to Mongo's _id? And so this search (which is against a valid
value) should have worked, no? Or am I not understanding something?
--
You received this message because you are subscribed to the Google Groups "doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
Loading...