# Entity Manager

Siteadmin uses Doctrine 2 as its internal ORM. All create/update/remove operations are handled through the doctrine entity manager context.

This is just a quick start guide to doctrine's entity manager. Visit the [official documentation](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html#starting-with-the-product-entity) for detailed explanations.

### Accessing Entity Manager Context

```php
// Returns doctrine entity manager instance
$entityManager = \sa\application\app::$entityManager
```

### Create/Update Entity

```php
<?php
// Create entity instance
$user = ioc::resolve('User');
​
// Set fields
$user->setFirstName('John')
     ->setLastName('Doe');
​
// Queue changes in entity manager
app::$entityManager->persist($user);
​
// Commit $user object specific changes
app::$entityManager->flush($user);
​
// Commit all persisted changes
app::$entityManager->flush();
```

### Remove Entity

```php
<?php
// $user is an entity which already exists in the entity manager.
app::$entityManager->remove($user);
```
