sonata-project/SonataAdminBundle — Issue #365: How to implement row level ownership
Author: ardianys
Created: 2011-11-01 09:38:02+00:00
State: open

Hi,

I need to passing logged in user object (especially user id) to my custom repository class,
I need to implement tutorial in this site

```
http://www.slideshare.net/jcleveley/working-with-the-admin-generator
````

page 46

It's something like

```
namespace Ardian\ProjectBundle\Repository

class TaskRepository extends EntityRepository

public function createQueryBuilder($alias)
{
/*
it doesn't work
*/
$admin_id = $this->get('security.context')->getToken()->getUser()->getId();

return $this->_em->createQueryBuilder()
->select($alias)
->from($this->_entityName, $alias)
->andWhere($alias.'.adminId = ? ', $admin_id);
}
```

Actually I can do this from my own function, but because it's not mine,
What best practice should I do ?

SonataAB createQuery function is only accept 1 parameter as alias,

```
namespace Sonata\AdminBundle\Model\ORM;

class ModelManager implements ModelManagerInterface

public function createQuery($class, $alias = 'o')
{
$repository = $this->getEntityManager()->getRepository($class);

return $repository->createQueryBuilder($alias);
}
```

Where should I make this change ? Should I replace this ModelManager class,

or what solution should I follow ?

Thanks for your answer.