[MODM-149] Fix PHPDoc @return types in various places Created: 05/Jul/11  Updated: 05/Apr/12

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Document Manager
Affects Version/s: 1.0.0BETA3
Fix Version/s: None

Type: Documentation Priority: Critical
Reporter: Dayson Pais Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

In certain PHPDoc blocks for functions, the @return type is not of the right type. This causes auto-completion issues in various IDEs (I'm using PhpStorm).

For example, in \Doctrine\ODM\MongoDB\DocumentManager on line #341 the ->createQueryBuilder($documentName = null) function.

/**

  • Create a new Query instance for a class.
    *
  • @param string $documentName The document class name.
  • @return Document\ODM\MongoDB\Query <--------------------------- MUST BE Query\Builder !
    */
    public function createQueryBuilder($documentName = null) { return new Query\Builder($this, $this->cmd, $documentName); }


 Comments   
Comment by Lee Davis [ 05/Apr/12 ]

This appears to be fixed in 1.0.0BETA4-DEV

Line 357 in Doctrine\ODM\MongoDB\DocumentManager...

/**

  • Create a new Query instance for a class.
    *
  • @param string $documentName The document class name.
  • @return Query\Builder
    */
    public function createQueryBuilder($documentName = null) { return new Query\Builder($this, $this->cmd, $documentName); }




[MODM-116] Collection Per Class Inheritance : Documents of a child class referenced in a parent class may be saved to the parent collection Created: 07/Feb/11  Updated: 21/Apr/11

Status: Reopened
Project: Doctrine MongoDB ODM
Component/s: Document Manager
Affects Version/s: 1.0.0BETA3
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: JF Bustarret Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Here is my class hierarchy (classes & attributes renamed for a better understanding) :

 
/** @Document @InheritanceType("COLLECTION_PER_CLASS") **/
class Parent {
    /** @ReferenceOne(targetDocument="Child") **/
    protected $child;
}

/** @Document **/
class Child extends Parent {
}

When doing :

$parent->setXXX($value);
$parent->getChild()->setXXX($value2)

the $parent->getChild() document is saved to the Parent collection.

It looks like the problems lies in UnitOfWork::executeUpdates :

 
if (get_class($document) == $className || $document instanceof Proxy && $document instanceof $className) {

$child_document is an instance of Proxy (ChildProxy) and also an instance of Parent => saved using the Parent persister.

Shouldn't the test be : get_class($document) == $className || get_class($document) == $className_of_Proxy ?

As a side note : why "if ($class->isEmbeddedDocument)

{ continue; }

" is within the foreach and not a "if ($class->isEmbeddedDocument)

{ return; }

" at the beginning of the method ?



 Comments   
Comment by Jonathan H. Wage [ 11/Feb/11 ]

I added a test for this here and it appears to be passing: https://github.com/doctrine/mongodb-odm/commit/3f24d77cc04adc0bb5532333e33826100457c666

Comment by JF Bustarret [ 11/Feb/11 ]

I'll try to get more info on the problem and provide a test for it.

Comment by JF Bustarret [ 28/Mar/11 ]

Here is a new test case :

 
/** @Document
 *  @InheritanceType("COLLECTION_PER_CLASS")
 **/
class MODM116Parent
{
    /** @Id */
    private $id;

    /** @String */
    private $name;

    /** @ReferenceOne **/
    private $child;

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getChild()
    {
        return $this->child;
    }

    public function setChild(MODM116Child $child)
    {
        $this->child = $child;
    }
}

/** @Document **/
class MODM116Child extends MODM116Parent
{
    
    /** @EmbedMany(targetDocument="MODM116Embedded") **/
    protected $embedded;
    
    function addEmbedded($parent) {
        $this->embedded[] = new MODM116Embedded($parent);
    }
}

/** @EmbeddedDocument **/
class MODM116Embedded {
    
    /** @ReferenceOne(targetDocument="MODM116Parent") **/
    protected $parent;
    
    public function __construct($parent) {
        $this->parent = $parent;
    }
    
}


$parent = new MODM116Parent();
$parent->setName('test');
$parent->setChild(new MODM116Child());
$dm->persist($parent->getChild());
$dm->persist($parent);
$dm->flush();
$dm->clear();

$parent = $dm->getRepository(get_class($parent))->findOneBy(array('name' => 'test'));

$parent->getChild()->setName('ok');
$parent->getChild()->addEmbedded($parent);
$dm->flush();
Comment by JF Bustarret [ 30/Mar/11 ]

Pulled the last version from git. The bug still exists.

Comment by JF Bustarret [ 21/Apr/11 ]

Up. Any news on a fix ?





[MODM-148] Do not add '$db' in reference when referencing document from same $db Created: 02/Jun/11  Updated: 02/Jun/11

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Document Manager
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Vladimir Razuvaev Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

When using ReferenceOne or ReferenceMany , doctrine will create fully-qualified reference to the object (with all fields: '$id', '$ref', '$db') even when reference is within same $db.

This approach causes several problems: for example we use mongo database as a template for new clients - when new client registers, template database is copied for him. But since it contains hardcoded $db - copy operation becomes resource consuming, since we have to loop through every document of every collection and fix $db reference.

Also maintenance suffers, since you can't easily rename database when required.

Is it possible to omit $db part when referencing document from same db?






[MODM-139] [PATCH] @ReferenceMany with no referenceMapping cannot handle DBRef in all / in queries Created: 08/Apr/11  Updated: 08/Apr/11

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Document Manager
Affects Version/s: 1.0.0BETA3
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Gérald Croes Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 1
Labels: None
Environment:

Linux, PHP 5.3



 Description   

I have thoose examples :

/** @Document 
 * @InheritanceType("SINGLE_COLLECTION")
 * @DiscriminatorField(fieldName="type")
 * @DiscriminatorMap({"Test\Product"="Product", "Test\Year"="Year"})
*/
Attributes {
   /** @Id */
   protected $_id;
}

/** @Document */
class Product extends Attributes {}

/** @Document */
class Year extends Attributes {}

/**
 * Classe de base pour les différents contenus
 * @Document
 * @InheritanceType("SINGLE_COLLECTION")
 * @DiscriminatorField(fieldName="type")
 * @DiscriminatorMap({"Test\Document"="Document", "Test\Infos"="Infos"})  
 */
class Content
{
   /** protected $_id */
    /** @ReferenceMany */
    protected $_attributes;
}

And the querying stuff

//and the query : 
$queryBuilder = $dm->createQueryBuilder('Test\DOcument');
//...
$attribute1Ref = $dm->createDBRef($attribute1Object);
$attribute2Ref = $dm->createDBRef($attribute2Object);
$queryBuilder->field('_attributes')->all(array($attribute1Ref, $attribute2Ref));
$queryBuilder->getQuery()->execute();//Won't work as the generated query won't specify the "_doctrine_class_name" value.

Proposed patch in DocumentManager :

    /**
     * Returns a DBRef array for the supplied document.
     *
     * @param mixed $document A document object
     * @param array $referenceMapping Mapping for the field the references the document
     *
     * @return array A DBRef array
     */
    public function createDBRef($document, array $referenceMapping = null)
    {
        $className = get_class($document);
        $class = $this->getClassMetadata($className);
        $id = $this->unitOfWork->getDocumentIdentifier($document);

        $dbRef = array(
            $this->cmd . 'ref' => $class->getCollection(),
            $this->cmd . 'id'  => $class->getDatabaseIdentifierValue($id),
            $this->cmd . 'db'  => $this->getDocumentDatabase($className)->getName()
        );

        // add a discriminator value if the referenced document is not mapped explicitely to a targetDocument
        if ($referenceMapping && ! isset($referenceMapping['targetDocument'])) {
            $discriminatorField = isset($referenceMapping['discriminatorField']) ? $referenceMapping['discriminatorField'] : '_doctrine_class_name';
            $discriminatorValue = isset($referenceMapping['discriminatorMap']) ? array_search($class->getName(), $referenceMapping['discriminatorMap']) : $class->getName();
            $dbRef[$discriminatorField] = $discriminatorValue;
+        }  elseif ($referenceMapping === null) {
+            $dbRef['_doctrine_class_name'] = $class->getName();
+        }
        return $dbRef;
    }





[MODM-169] Filter API is not unified between ODM and ORM Created: 10/Dec/12  Updated: 10/Dec/12

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Document Manager
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Craig Marvelley Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Hi,

I'm implementing some functionality around filters which will ideally work for both ORM and ODM. The API for managing filters is different on `Doctrine\ORM\EntityManager` and `Doctrine\ODM\MongoDB\DocumentManager`, while the CouchDB implementation of ODM has no filter concept.

For example, ORM EntityManager has getFilters(), hasFilters(), while ODM MongoDB DocumentManager has getFilterCollection().

I was wondering what your thoughts were on defining the filter API in an interface, to improve consistency when implementing cross-library functionality?

Thanks,
Craig






Generated at Wed May 22 05:01:25 UTC 2013 using JIRA 5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5.