[MODM-178] Add an event that allows adjustment of a query prior to being executed Created: 03/Jan/14  Updated: 03/Jan/14

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Query Builder
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Westin Pigott Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I would like to add an event which is triggered upon the creation of a query, and prior to the query being executed. This would allow the query to be modified prior to execution.

This would be useful in the following use case (off the top of my head):

  1. A developer needs to set the scope of a query. An example would be: In a white-label site situation where you want to make sure the login only checks for the correct user in the scope of the domain. Rather than needing to make sure that every query has the scope added when the query is defined, the scope could be added prior to execution.
  2. Users want to enable encryption on certain fields. The encrypting and decrypting part are fairly straight-forward using the existing events. The problem is encountered when you have to be aware of the encryption when composing a query. If we could modify the query prior to execution, we could check the fields and adjust the search values as needed.


 Comments   
Comment by Westin Pigott [ 03/Jan/14 ]

BTW, if you point me in the general direction, I would be happy to do the work on this issue.





[MODM-176] includesReferenceTo query failure Created: 09/Nov/13  Updated: 20/Jan/14

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Query Builder
Affects Version/s: 1.0.0BETA2
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Hussain Nazan Naeem Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: dql
Environment:

MongoDB shell version: 2.4.6



 Description   

Problem explained below as an example.
Suppose Car model has referenceMany relation with Wheel model.

/** @ReferenceMany(targetDocument="Wheel", inversedBy="car", simple=true) */
protected $wheels

note the simple=true param. If this param is specified then includesReferenceTo queries fail for Car model.

For example, following query fails:

$cars = $dm->createQueryBuilder('Car')
            ->field('wheels')
            ->includesReferenceTo($wheel)
            ->getQuery()
            ->execute();





[MODM-145] QueryBuilder references() to does not support references on embedded objects' fields Created: 23/May/11  Updated: 25/Oct/11

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Query Builder
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Jeremy Mikola Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I noticed that the references() method does not support fields on embedded objects, as the argument to the preceding field() method will be passed into getFieldMapping() and trigger an exception. I suppose a solution would require multiple calls to getFieldMapping() in order to dive into the embedded object's class metadata.

To demonstrate, below is an example of a UserRepository class. The User document contains an embeddedObject that itself references another User:

class UserRepository extends DocumentRepository
{ 
    public function findByEmbeddedObjectReference(User $user)
    {
        return $this->createQueryBuilder()
            ->field('embeddedObject.user.$id')->equals($user->getId())
//          ->field('embeddedObject.user')->references($user)
            ->getQuery()
            ->execute();
    }
}

Using field()/equals() works fine as an alternative to references(), so there is no urgent need for this feature.



 Comments   
Comment by Nicolas Brignol [ 25/Oct/11 ]

Hi

It seems that we have a problem with the temporary solution proposed :
Doctrine remove the "$id" part in our query :

   obj->field('embedded.referenced.$id')->equals($reference->getId())

will generate the query without "$id".
There is no problem when the reference is directly in the requested object.

Did someone experience this issue ?





Generated at Thu Oct 30 18:25:23 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.