Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Contacts
- *
- * @ORMTable(name="contacts")
- * @ORMEntity(repositoryClass="AppBundleRepositoryContactsRepository")
- */
- class Contacts
- {
- ....
- /**
- * @var DoctrineCommonCollectionsCollection
- *
- * @ORMManyToMany(targetEntity="AppBundleEntityMedias", inversedBy="contact")
- * @ORMJoinTable(name="contacts_has_medias",
- * joinColumns={
- * @ORMJoinColumn(name="contact_id", referencedColumnName="id")
- * },
- * inverseJoinColumns={
- * @ORMJoinColumn(name="media_id", referencedColumnName="id")
- * }
- * )
- */
- private $media;
- ....
- class ContactsRepository extends EntityRepository
- {
- public function getContacts()
- {
- return $this->getEntityManager()
- ->createQuery(
- 'SELECT c FROM AppBundle:Contact c ORDER BY c.Name ASC'
- )
- ->getResult();
- }
- public function getContact($idContact)
- {
- $qb = $this->createQueryBuilder('c')
- ->andWhere('c.id = :idContact')
- ->setParameter('idContact', $idContact);
- $query = $qb->getQuery();
- return $query->execute();
- }
- }
- /**
- * Medias
- *
- * @ORMTable(name="medias")
- * @ORMEntity
- */
- class Medias
- {
- /**
- * @var integer
- *
- * @ORMColumn(name="id", type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMOneToMany(targetEntity="AppBundleEntityCharges", mappedBy="media", cascade={"ALL"}, indexBy="contact")
- */
- private $charge;
- ....
- /**
- * Charges
- *
- * @ORMTable(name="charges")
- * @ORMEntity
- * @UniqueEntity(fields={"contact_id", "media_id"})
- */
- class Charges
- {
- /**
- * @var string
- *
- * @ORMColumn(name="charge", type="string", length=255, nullable=true)
- */
- private $charge;
- /**
- * @ORMId
- * @ORMManyToOne(targetEntity="AppBundleEntityContacts")
- * @ORMGeneratedValue(strategy="NONE")
- */
- private $contact;
- /**
- * @ORMId
- * @ORMManyToOne(targetEntity="AppBundleEntityMedias", inversedBy="charge")
- * @ORMGeneratedValue(strategy="NONE")
- */
- private $media;
- public function __construct(Contact $contact, Media $media, $charge)
- {
- $this->media = $media;
- $this->contact = $contact;
- $this->charge = $charge;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement