njr03304/doctrine-repository-bundle

Symfony njr03304 DoctrineRepositoryBundle

dev-master / 1.1.x-dev 2016-09-17 00:56 UTC

This package is not auto-updated.

Last update: 2025-01-22 21:51:17 UTC


README

Currently, this project just includes a single trait to use in a Doctrine repository.

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require njr03304/doctrine-repository-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

namespace AppBundle\Repository;

use njr03304\DoctrineRepositoryBundle\Repository\Traits\FindAndCreateTrait;

class TagRepository extends \Doctrine\ORM\EntityRepository
{
    use FindAndCreateTrait;
}
$entity = $em->getRepository('AppBundle:Tag')->findByElseCreate(array('name' => 'example'));

$entity will now be and instance of AppBundle\Entity\Tag with a name of 'example', either from the DB or a new instance ready to be saved to the DB.