njr03304 / doctrine-repository-bundle
Symfony njr03304 DoctrineRepositoryBundle
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4
- doctrine/doctrine-bundle: ~1.3
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.