Symfony3 - Left Join does not work properly - symfony

Trying to solve this problem with Join in Symfony3.
Somehow the resultset has mixed up values, i.e
ID Exploit Author
ID Author Author
Please see the attached screenshot.
OpenX should have Author Metasploit and the second row shouldn't be there.
Have this code in the controller:
public function indexAction()
{
$exploits = $this->getDoctrine()
->getRepository('AppBundle:Exploit')->createQueryBuilder('e')
->add('select', 'a,e')
->add('from', 'AppBundle:Exploit e')
->leftJoin('AppBundle:Author', 'a')
->where('e.author = a.id')
->getQuery()
->getResult();
return $this->render('exploit/index.html.twig', array(
'exploits' => $exploits
));
}
This view:
<tbody>
{% for exploit in exploits %}
<tr>
<th scope="row">{{ exploit.id }}</th>
<td>{{ exploit.name }}</td>
<td> {{ exploit.author }} </td>
<td>
View
Edit
Delete
</td>
</tr>
{% endfor %}
And these Entities:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Author
*
* #ORM\Table(name="author", indexes={#ORM\Index(name="author_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Author
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="author")
* })
*/
private $id;
/**
* Set name
*
* #param string $name
*
* #return Author
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function getAuthor()
{
return $this->name;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Author
*
* #ORM\Table(name="author", indexes={#ORM\Index(name="author_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Author
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="author")
* })
*/
private $id;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Category
*
* #ORM\Table(name="category", indexes={#ORM\Index(name="category_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Category
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="category")
* })
*/
private $id;
/**
* Set name
*
* #param string $name
*
* #return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Category
*
* #ORM\Table(name="category", indexes={#ORM\Index(name="category_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Category
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="category")
* })
*/
private $id;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Exploit
*
* #ORM\Table(name="exploit", indexes={#ORM\Index(name="exploit_category_idx", columns={"category"}), #ORM\Index(name="exploit_type_idx", columns={"type"}), #ORM\Index(name="exploit_author_idx", columns={"author"})})
* #ORM\Entity
*/
class Exploit
{
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="edb_id", type="string", length=100, nullable=false)
*/
private $edbId;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime", nullable=false)
*/
private $date;
/**
* #var integer
*
* #ORM\Column(name="author", type="bigint", nullable=false)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var integer
*
* #ORM\Column(name="category", type="bigint", nullable=false)
*/
private $category;
/**
* #var string
*
* #ORM\Column(name="version", type="string", length=255, nullable=false)
*/
private $version;
/**
* #var integer
*
* #ORM\Column(name="type", type="bigint", nullable=false)
*/
private $type;
/**
* #var string
*
* #ORM\Column(name="content", type="text", nullable=false)
*/
private $content;
/**
* #var string
*
* #ORM\Column(name="dork", type="string", length=255, nullable=true)
*/
private $dork;
/**
* #var string
*
* #ORM\Column(name="software_link", type="string", length=255, nullable=true)
*/
private $softwareLink;
/**
* #var string
*
* #ORM\Column(name="tested_on", type="string", length=255, nullable=true)
*/
private $testedOn;
/**
* Set edbId
*
* #param integer $edbId
*
* #return Exploit
*/
public function setEdbId($edbId)
{
$this->edbId = $edbId;
return $this;
}
/**
* Get edbId
*
* #return integer
*/
public function getEdbId()
{
return $this->edbId;
}
/**
* Set date
*
* #param \DateTime $date
*
* #return Exploit
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* #return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set author
*
* #param integer $author
*
* #return Exploit
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return integer
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set name
*
* #param string $name
*
* #return Exploit
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set category
*
* #param integer $category
*
* #return Exploit
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* #return integer
*/
public function getCategory()
{
return $this->category;
}
/**
* Set version
*
* #param string $version
*
* #return Exploit
*/
public function setVersion($version)
{
$this->version = $version;
return $this;
}
/**
* Get version
*
* #return string
*/
public function getVersion()
{
return $this->version;
}
/**
* Set type
*
* #param integer $type
*
* #return Exploit
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return integer
*/
public function getType()
{
return $this->type;
}
/**
* Set content
*
* #param string $content
*
* #return Exploit
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set dork
*
* #param string $dork
*
* #return Exploit
*/
public function setDork($dork)
{
$this->dork = $dork;
return $this;
}
/**
* Get dork
*
* #return string
*/
public function getDork()
{
return $this->dork;
}
/**
* Set softwareLink
*
* #param string $softwareLink
*
* #return Exploit
*/
public function setSoftwareLink($softwareLink)
{
$this->softwareLink = $softwareLink;
return $this;
}
/**
* Get softwareLink
*
* #return string
*/
public function getSoftwareLink()
{
return $this->softwareLink;
}
/**
* Set testedOn
*
* #param string $testedOn
*
* #return Exploit
*/
public function setTestedOn($testedOn)
{
$this->testedOn = $testedOn;
return $this;
}
/**
* Get testedOn
*
* #return string
*/
public function getTestedOn()
{
return $this->testedOn;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Exploit
*
* #ORM\Table(name="exploit", indexes={#ORM\Index(name="exploit_category_idx", columns={"category"}), #ORM\Index(name="exploit_type_idx", columns={"type"}), #ORM\Index(name="exploit_author_idx", columns={"author"})})
* #ORM\Entity
*/
class Exploit
{
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="edb_id", type="string", length=100, nullable=false)
*/
private $edbId;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime", nullable=false)
*/
private $date;
/**
* #var integer
*
* #ORM\Column(name="author", type="bigint", nullable=false)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var integer
*
* #ORM\Column(name="category", type="bigint", nullable=false)
*/
private $category;
/**
* #var string
*
* #ORM\Column(name="version", type="string", length=255, nullable=false)
*/
private $version;
/**
* #var integer
*
* #ORM\Column(name="type", type="bigint", nullable=false)
*/
private $type;
/**
* #var string
*
* #ORM\Column(name="content", type="text", nullable=false)
*/
private $content;
/**
* #var string
*
* #ORM\Column(name="dork", type="string", length=255, nullable=true)
*/
private $dork;
/**
* #var string
*
* #ORM\Column(name="software_link", type="string", length=255, nullable=true)
*/
private $softwareLink;
/**
* #var string
*
* #ORM\Column(name="tested_on", type="string", length=255, nullable=true)
*/
private $testedOn;
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Type
*
* #ORM\Table(name="type", indexes={#ORM\Index(name="type_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Type
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="type")
* })
*/
private $id;
/**
* Set name
*
* #param string $name
*
* #return Type
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Type
*
* #ORM\Table(name="type", indexes={#ORM\Index(name="type_name_id_idx", columns={"id"})})
* #ORM\Entity
*/
class Type
{
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var \Exploit
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Exploit")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="id", referencedColumnName="type")
* })
*/
private $id;
}
Anybody know how to correct my join query ? Or why it behaves like this?
Thanks,

Try this:
->leftJoin('AppBundle:Author', 'a', "WITH", "e.author = a.id")
Instead of this:
->leftJoin('AppBundle:Author', 'a')
->where('e.author = a.id')

Try
public function indexAction()
{
$exploits = $this->getDoctrine()
->getRepository('AppBundle:Exploit')->createQueryBuilder('e')
->leftjoin('e.author','a')
->addSelect('a')
->getQuery()
->getResult();
return $this->render('exploit/index.html.twig', array(
'exploits' => $exploits
));
}
and in the view
<tbody>
{% for exploit in exploits %}
<tr>
<th scope="row">{{ exploit.id }}</th>
<td>{{ exploit.name }}</td>
<td> {{ exploit.author.name }} </td>
<td>
View
Edit
Delete
</td>
</tr>
{% endfor %}
</tbody>

Related

Symfony Circular Reference Exception with Doctrine tree extension

I have a Circular Reference Exception because of Doctrine Tree Extension when I'm tring to load my fixture with Alice fixture.
[Doctrine\Common\DataFixtures\Exception\CircularReferenceException]
Graph contains cyclic dependency. An example of this problem would be
the following: Class C has class B as its dependency. Then, class B
has class A has its dependency. Finally, class A has class C as
its dependency.
I have found the same problem here:
https://github.com/doctrine/data-fixtures/issues/232 but the solution does not work for me :( ...
I'm using this version of the doctrine fixtures.
"doctrine/data-fixtures": "1.2.1",
Here is my entity
namespace BaseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* BaseCategory
*
* #ORM\Entity()
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="type", type="string")
* #ORM\DiscriminatorMap({
* "article_category" = "AppBundle\Entity\ArticleCategory",
* "page_category" = "AppBundle\Entity\PageCategory",
* })
* #Gedmo\Tree(type="nested")
*/
abstract class BaseCategory
{
use \BaseBundle\Traits\SeoTrait;
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
* #Assert\NotBlank()
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="slug", type="string", length=255, unique=true)
* #Gedmo\Slug(fields={"title"})
*/
private $slug;
/**
* #var string
*
* #ORM\Column(name="description", type="text")
*/
private $description;
/**
* #var \DateTime
*
* #ORM\Column(type="datetime")
* #Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* #var \DateTime
*
* #ORM\Column(type="datetime")
* #Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* #Gedmo\TreeLeft
* #ORM\Column(type="integer")
*/
private $lft;
/**
* #Gedmo\TreeLevel
* #ORM\Column(type="integer")
*/
private $lvl;
/**
* #Gedmo\TreeRight
* #ORM\Column(type="integer")
*/
private $rgt;
/**
* #Gedmo\TreeRoot
* #ORM\ManyToOne(targetEntity="BaseCategory")
* #ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
*/
private $root;
/**
* #Gedmo\TreeParent
* #ORM\ManyToOne(targetEntity="BaseCategory", inversedBy="children")
* #ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* #ORM\OneToMany(targetEntity="BaseCategory", mappedBy="parent")
* #ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return BaseCategory
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set slug
*
* #param string $slug
*
* #return BaseCategory
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* #return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set description
*
* #param string $description
*
* #return BaseCategory
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* #return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function getRoot()
{
return $this->root;
}
public function setParent(BaseCategory $parent = null)
{
$this->parent = $parent;
}
public function getParent()
{
return $this->parent;
}
}
Is it normal? How can I fix that?

Runtime Notice: Accessing static property Proxies\__CG__\SimpleMediaBundle\Entity\Media::$lazyPropertiesDefaults as non static

I created a custom bundle called SimpleMedia. When I try to load a page that loads a company it gives me the Runtime Notice
Runtime Notice: Accessing static property Proxies__CG__\SimpleMediaBundle\Entity\Media::$lazyPropertiesDefaults as non static.
I know it has something to do with my one to one relation
(logoFile(Company Entity) -> id (Media Entity).
Anyone have any ideas? I am using Symfony 2.7
Controller
/**
* #Route("/{id}", name="api_company_show")
* #Method("GET")
* #param $id
* #return Response $response
*/
public function showAction($id) {
$company = $this->findCompanyById($id);
$response = $this->createApiResponse($company, 200);
return $response;
}
/**
* Find company by id. Throw exception if it does not.
* #param $id
* #return Company $company
*/
private function findCompanyById($id) {
$company = $this->getDoctrine()
->getRepository('AppBundle:Company')
->find($id);
if (!$company) {
throw $this->createNotFoundException(sprintf(
'No company found with id "%d"',
$id
));
}
return $company;
}
Company.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Entity\User;
use Symfony\Component\HttpFoundation\File\File;
use SimpleMediaBundle\Entity\Media;
/**
* Company
* #ORM\Table()
* #ORM\Entity(repositoryClass="AppBundle\Repository\CompanyRepository")
*/
class Company
{
/**
* #var integer
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
* #ORM\Column(name="website", type="string", length=255, nullable=true)
*/
private $website;
/**
* #var string
* #ORM\Column(name="address_1", type="string", length=255, nullable=true)
*/
private $address1;
/**
* #var string
* #ORM\Column(name="address_2", type="string", length=255, nullable=true)
*/
private $address2;
/**
* #var string
* #ORM\Column(name="city", type="string", length=255, nullable=true)
*/
private $city;
/**
* #var string
* #ORM\Column(name="state", type="string", length=255, nullable=true)
*/
private $state;
/**
* #var string
* #ORM\Column(name="zipcode", type="string", length=50, nullable=true)
*/
private $zipcode;
/**
* #var string
* #ORM\Column(name="country", type="string", length=255, nullable=true)
*/
private $country;
/**
* #var string
* #ORM\Column(name="phone", type="string", length=50, nullable=true)
*/
private $phone;
/**
* #var string
* #ORM\Column(name="fax", type="string", length=50, nullable=true)
*/
private $fax;
/**
* #var integer
* #ORM\Column(name="years_in_business", type="integer", length=50, nullable=true)
*/
private $yearsInBusiness;
/**
* #var string
* #ORM\Column(name="number_of_employees", type="integer", length=50, nullable=true)
*/
private $numberOfEmployees;
/**
* #var integer
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\User")
*/
private $owners;
/**
* #ORM\OneToOne(targetEntity="SimpleMediaBundle\Entity\Media", cascade={"persist", "remove"}, orphanRemoval=true)
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="logo_file", referencedColumnName="id", nullable=true)
* })
*/
protected $logoFile;
/**
* #ORM\Column(type="datetime", name="updated", nullable=true)
* #var \DateTime $updated
*/
protected $updated;
public function __construct()
{
$this->owners = new ArrayCollection();
$this->logoFile = new ArrayCollection();
}
/**
* Get id
* #return integer
*/
public function getId()
{
return $this->id;
}
// Basic Getter and Setters
/**
* Set logo file id.
* #param Media $media
* #return $this
*/
public function setLogoFile(Media $media)
{
$this->logoFile = $media;
return $this;
}
/**
* Get Log File.
* #return File
*/
public function getLogoFile()
{
return $this->logoFile;
}
}
Media.php
namespace SimpleMediaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use SimpleMediaBundle\Entity\MediaInterface;
/**
* #ORM\Table()
* #ORM\Entity(repositoryClass="SimpleMediaBundle\Repository\MediaRepository")
*/
class Media implements MediaInterface
{
/**
* #var integer $id
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $name
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string $path
* #ORM\Column(name="path", type="string", length=500)
*/
private $path;
/**
* #var string $size
* #ORM\Column(name="size", type="integer", nullable=true)
*/
private $size;
/**
* #var string $createdAt
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* #var string $createdAt
* #ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/**
* #var string $contentType
* #ORM\Column(name="content_type", type="string", length=50, nullable=true)
*/
private $contentType;
/**
* #var string $type
* #ORM\Column(name="type", type="string", length=255)
*/
private $type;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
/**
* Get id
* #return integer
*/
public function getId()
{
return $this->id;
}
// Basic Getter and Setters
/**
* Transform to string
* #return string
*/
public function __toString()
{
return (string) $this->getId();
}
}
Changing the fetch mode to EAGER fixed the issue for me.
/**
* #var Media
*
* #ORM\OneToOne(targetEntity="SimpleMediaBundle\Entity\Media", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EAGER")
* #ORM\JoinColumn(name="logo_file", referencedColumnName="id", nullable=true)
*/
private $logoFile;
I think you have define the relationship wrong. I think should be:
/**
*
* #ORM\OneToOne(targetEntity="SimpleMediaBundle\Entity\Media", cascade={"persist", "remove"}, orphanRemoval=true)
* #ORM\JoinColumn(name="logo_file", referencedColumnName="id", nullable=true)
*/
protected $logoFile;
On the other hand, in the company constructor you dont need initialiser the $logoFile variable because is not a array it is just one value.

Doctrine OneToOne remove entity

When I remove entity, relations OneToOne has not been removed. Gallery has been removed successfully from database, but largeImage, mediumImage and smallImage not.
What I do wrong?
Delete action in controller:
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$offer = $em->getRepository('ToCmsBundle:Offer')->find($id);
if($offer) {
if(!$offer->getGallery()->isEmpty()) {
foreach($offer->getGallery() as $key => $image) {
$image->setOffer(null);
$offer->removeGallery($image);
//$em->remove($image);
//$em->flush();
echo $image->getPath() . '<br/>';
}
} else {
echo 'gallery is empty';
}
$offer->setLargeImage(null);
$offer->setMediumImage(null);
$offer->setSmallImage(null);
$em->remove($offer);
$em->flush();
}
return $this->redirect($this->generateUrl('to_offer_list'));
}
My owner class:
/**
* Offer
*
* #ORM\Table(name="to_offer")
* #ORM\HasLifecycleCallbacks
* #ORM\Entity(repositoryClass="To\CmsBundle\Repository\OfferRepository")
*/
class Offer {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="Image", mappedBy="offer", cascade={"all"}, orphanRemoval=true)
*/
private $gallery;
/**
* #var Image
*
* #ORM\OneToOne(targetEntity="Image", cascade={"all"}, orphanRemoval=true)
*/
public $largeImage;
/**
* #var Image
*
* #ORM\OneToOne(targetEntity="Image", cascade={"all"}, orphanRemoval=true)
*/
public $mediumImage;
/**
* #var Image
*
* #ORM\OneToOne(targetEntity="Image", cascade={"all"}, orphanRemoval=true)
*/
public $smallImage;
/**
* #var ArrayCollection
*
* #ORM\ManyToMany(targetEntity="Category", inversedBy="articles")
* #ORM\JoinTable(name="to_articles_categories")
*/
private $categories;
/**
* #var User
*
* #ORM\ManyToOne(targetEntity="User")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id")
*/
private $author;
public function __construct() {
$this->gallery = new ArrayCollection();
$this->categories = new ArrayCollection();
}
/** other stuff */
}
Image class:
/**
* Image
*
* #ORM\Table(name="to_images")
* #ORM\Entity(repositoryClass="To\CmsBundle\Repository\ImageRepository")
* #ORM\HasLifecycleCallbacks
*/
class Image
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="hashName", type="string", length=255)
*/
private $hashName;
/**
* #var integer
*
* #ORM\Column(name="position", type="integer")
*/
private $position;
/**
* #var string
*
* #ORM\Column(name="path", type="string", length=255)
*/
private $path;
/**
* #var string
*
* #ORM\Column(name="thumbnail", type="string", length=255)
*/
private $thumbnail;
/**
* #var string
*
* #ORM\Column(name="originalImage", type="string", length=255)
*/
private $originalImage;
/**
* #var Offer
*
* #ORM\ManyToOne(targetEntity="Offer", inversedBy="gallery")
* #ORM\JoinColumn(name="offer_id", referencedColumnName="id", nullable=true)
*/
private $offer;
/**
* #var \DateTime
*
* #Gedmo\Timestampable(on="create")
* #ORM\Column(name="createdAt", type="datetime")
*/
private $createdAt;
/**
* #var \DateTime
*
* #Gedmo\Timestampable(on="update")
* #ORM\Column(name="updatedAt", type="datetime")
*/
private $updatedAt;
/**
* #var integer
*
* #ORM\Column(name="x", type="integer")
*/
protected $x = 0;
/**
* #var integer
*
* #ORM\Column(name="y", type="integer")
*/
protected $y = 0;
/**
* #var integer
*
* #ORM\Column(name="w", type="integer")
*/
protected $w = 0;
/**
* #var integer
*
* #ORM\Column(name="h", type="integer")
*/
protected $h = 0;
/**
* #var boolean
*
* #ORM\Column(name="defaultImage", type="boolean")
*/
private $default = 0;
public function __construct() {
$this->position = 0;
$this->default = 0;
$this->x = 0;
$this->y = 0;
}
/**
* #ORM\PrePersist()
* #ORM\PreUpdate()
*/
public function preUpload()
{
$this->position = $this->position ?: 0;
$this->default = $this->default ?: 0;
$this->x = $this->x ?: 0;
$this->y = $this->y ?: 0;
/*if (null !== $this->getFile()) {
// do whatever you want to generate a unique name
$this->name = sha1(uniqid(mt_rand(), true));
$this->originName = $this->getFile()->getClientOriginalName();
$this->extension = $this->getFile()->guessExtension();
$this->path = $this->name.'.'.$this->extension;
}*/
}
/**
* #ORM\PreRemove()
*/
public function removeUpload()
{
echo $this->getRootPath().$this->originalImage; echo '<br/>';
echo $this->getRootPath().$this->thumbnail; echo '<br/>';
echo $this->getRootPath().$this->path; echo '<br/>';
echo '<br/><br/>';
if(file_exists($this->getRootPath().$this->originalImage))
unlink($this->getRootPath().$this->originalImage);
if(file_exists($this->getRootPath().$this->thumbnail))
unlink($this->getRootPath().$this->thumbnail);
if(file_exists($this->getRootPath().$this->path))
unlink($this->getRootPath().$this->path);
}
/** other stuff */
}
Your entities are referencing each other so you should try remove these :
$offer->setLargeImage(null);
$offer->setMediumImage(null);
$offer->setSmallImage(null);
and call flush() once before $em->remove($offer); and once after.
foreach ($offer->getGallery() as $image) {
$offer->removeGallery($image);
}
$em->flush();
$em->remove($offer);
$em->flush();
This will only work as is if all the images are "privately owned", meaning that they are not referenced multiple times in this entity or in another entity.
$offer->setLargeImage(null);
$offer->setMediumImage(null);
$offer->setSmallImage(null);
Your "$offer" doesn't have the images anymore when you're deleting it.
UPDATE
When you are doing your 'find()' you don't have the image object, but a proxy because of the lazy loading. If you need the offer with image objects, create a query with leftJoin on the images to get the offer AND images. And then, I think that you'll not have problems.
(look at the end of this tutorial to have an example of a leftjoin on objects : http://symfony.com/fr/doc/current/cookbook/security/entity_provider.html#gerer-les-roles-via-la-base-de-donnees)

How can translatable in many-to-many relationship in Doctrine2? Symfony2

I've used Translatable with a personal translation; I've implemented PysTranslationand I've used ORM query hint in PysRepository. All of this works fine, the problem has been when I've translated the entity Genero. This entity has a many-to-many relationship with Pys entity and the above method doesn't work. How I can translate the $genNombre attribute of Generoentity?
/**
* Pys
*
* #ORM\Table(name="pys")
* #ORM\Entity(repositoryClass="Filmboot\PYSBundle\Entity\PysRepository")
* #Gedmo\TranslationEntity(class="Filmboot\PYSBundle\Entity\PysTranslation")
*/
class Pys
{
/**
* #var integer
*
* #ORM\Column(name="PYS_ID", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $pysId;
/**
* #var string
*
* #ORM\Column(name="PYS_STR", type="string", length=255, nullable=false)
* #Gedmo\Translatable
*/
private $pysStr;
/**
* #var string
*
* #ORM\Column(name="PYS_TITULO", type="string", length=255, nullable=true)
* #Gedmo\Translatable
*/
private $pysTitulo;
/**
* #var integer
*
* #ORM\Column(name="PYS_DURACION", type="integer", nullable=true)
*/
private $pysDuracion;
/**
* #var integer
*
* #ORM\Column(name="PYS_ANYO", type="integer", nullable=true)
*/
private $pysAnyo;
/**
* #var string
*
* #ORM\Column(name="PYS_PAIS", type="string", length=255, nullable=true)
* #Gedmo\Translatable
*/
private $pysPais;
/**
* #var string
*
* #ORM\Column(name="PYS_SINOPSIS", type="string", length=3000, nullable=true)
* #Gedmo\Translatable
*/
private $pysSinopsis;
/**
* #var string
*
* #ORM\Column(name="PYS_GUIONISTA", type="string", length=255, nullable=true)
*/
private $pysGuionista;
/**
* #ORM\ManyToOne(targetEntity="Filmboot\DirectorBundle\Entity\Director", cascade={"remove"})
* #ORM\JoinColumn(name="DIR_ID", referencedColumnName="DIR_ID", onDelete="CASCADE")
*/
private $director;
/**
* #var string
*
* #ORM\Column(name="PYS_IMAGEN", type="string", length=255, nullable=true)
*/
private $pysImagen;
/**
* #var string
*
* #ORM\Column(name="PYS_IMAGEN_GRANDE", type="string", length=255, nullable=true)
*/
private $pysImagenGrande;
/**
* #ORM\ManyToMany(targetEntity="\Filmboot\ActorBundle\Entity\Actor", mappedBy="peliculas", cascade={"remove"})
*/
private $actores;
/**
* #ORM\ManyToMany(targetEntity="\Filmboot\PYSBundle\Entity\Genero", mappedBy="peliculas", cascade={"remove"})
*/
private $generos;
/**
* #ORM\OneToMany(targetEntity="\Filmboot\PYSBundle\Entity\Premio", mappedBy="pys", cascade={"remove"})
* #ORM\JoinColumn(name="PRE_ID", referencedColumnName="PRE_ID", onDelete="CASCADE")
*/
private $premios;
/**
* #ORM\OneToMany(targetEntity="\Filmboot\UsuarioBundle\Entity\Voto", mappedBy="pys", cascade={"remove"})
* #ORM\JoinColumn(name="PYS_ID", referencedColumnName="PYS_ID", onDelete="CASCADE")
*/
private $votaciones;
/**
* #ORM\OneToMany(targetEntity="PysTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
private $translations;
public function __construct()
{
$this->actores = new ArrayCollection();
$this->generos = new ArrayCollection();
$this->votaciones = new ArrayCollection();
$this->translations = new ArrayCollection();
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(PysTranslation $t)
{
if (!$this->translations->contains($t)) {
$this->translations[] = $t;
$t->setObject($this);
}
}
This is Genero
<?php
namespace Filmboot\PYSBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Genero
*
* #ORM\Table(name="genero")
* #ORM\Entity
*/
class Genero
{
/**
* #var integer
*
* #ORM\Column(name="GEN_ID", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $genId;
/**
* #var string
*
* #ORM\Column(name="GEN_NOMBRE", type="string", length=255, nullable=true)
* #Gedmo\Translatable
*/
private $genNombre;
/**
* #ORM\ManyToMany(targetEntity="\Filmboot\PYSBundle\Entity\Pys", inversedBy="generos")
* #ORM\JoinTable(name="P_GENERO",
* joinColumns={#ORM\JoinColumn(name="GEN_ID", referencedColumnName="GEN_ID")},
* inverseJoinColumns={#ORM\JoinColumn(name="PYS_ID", referencedColumnName="PYS_ID")}
* )
*/
private $peliculas;
This is PysTranslation
/**
* #ORM\Entity
* #ORM\Table(name="pys_translation", uniqueConstraints={#ORM\UniqueConstraint(name="lookup_unique_idx", columns={"locale", "object_id", "field"})})
*/
class PysTranslation extends AbstractPersonalTranslation
{
/**
* Convinient constructor
*
* #param string $locale
* #param string $field
* #param string $value
*/
public function __construct($locale, $field, $value)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($value);
}
/**
* #ORM\ManyToOne(targetEntity="Pys", inversedBy="translations")
* #ORM\JoinColumn(name="object_id", referencedColumnName="PYS_ID", onDelete="CASCADE")
*/
protected $object;
}
This is PysRepository
class PysRepository extends EntityRepository
{
public function findPeliculas()
{
$em = $this->getEntityManager();
$consulta = $em->createQuery('
SELECT p, a, d, g, pr, v
FROM PYSBundle:Pys p
JOIN p.actores a JOIN p.director d JOIN p.generos g JOIN p.premios pr JOIN p.votaciones v
ORDER BY p.pysTitulo ASC
');
return $consulta->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker')->getResult();
}
/**
*
* #param string $pysStr El slug de la pelĂ­cula
*/
public function findPys($pysStr)
{
$em = $this->getEntityManager();
$consulta = $em->createQuery('
SELECT p, a, d, g, pr, v
FROM PYSBundle:Pys p
JOIN p.actores a JOIN p.director d JOIN p.generos g JOIN p.premios pr JOIN p.votaciones v
WHERE p.pysStr = :pysStr
');
$consulta->setParameter('pysStr', $pysStr);
return $consulta->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker')->getSingleResult();
}
}
I've solved the problem by adding this line in Genero entity annotations:
/**
* Genero
*
* #ORM\Table(name="genero")
* #ORM\Entity
* #Gedmo\TranslationEntity(class="Filmboot\PYSBundle\Entity\GeneroTranslation")
*/
class Genero

Symfony2: Query the database with Doctrine

I have a small database connected with my Symfony2 project. I have my controller, the entity etc.
When I try to use the method find(), I am allways obtaining a null.
Here is how the find method is called:
public function loginsuccessAction()
{
$em = $this->getDoctrine()->getEntityManager();
$user = $em->getRepository('MDPILoginBundle:Users')->find(1);
var_dump($user);
}
My Users entity class has the needed getters and setters. My table Users is well populated.
What am I missing ? New with symfony, I am trying to do it for the first time, reading some tutorials.
Thank you very much.
PS: If you need more details, please feel free to ask me.
EDIT: Entity Users.php added
Here is the Users.php entity
<?php
namespace MDPI\LoginBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MDPI\LoginBundle\Entity\Users
*
* #ORM\Table(name="users")
* #ORM\Entity
*/
class Users
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var integer $editorId
*
* #ORM\Column(name="editor_id", type="integer", nullable=true)
*/
private $editorId;
/**
* #var string $email
*
* #ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* #var string $password
*
* #ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* #var integer $titleId
*
* #ORM\Column(name="title_id", type="integer", nullable=true)
*/
private $titleId;
/**
* #var string $firstname
*
* #ORM\Column(name="firstname", type="string", length=255, nullable=true)
*/
private $firstname;
/**
* #var string $lastname
*
* #ORM\Column(name="lastname", type="string", length=255, nullable=true)
*/
private $lastname;
/**
* #var string $department
*
* #ORM\Column(name="department", type="string", length=255, nullable=true)
*/
private $department;
/**
* #var string $organization
*
* #ORM\Column(name="organization", type="string", length=255, nullable=true)
*/
private $organization;
/**
* #var string $address1
*
* #ORM\Column(name="address1", type="string", length=255, nullable=true)
*/
private $address1;
/**
* #var string $address2
*
* #ORM\Column(name="address2", type="string", length=255, nullable=true)
*/
private $address2;
/**
* #var string $city
*
* #ORM\Column(name="city", type="string", length=50, nullable=true)
*/
private $city;
/**
* #var string $state
*
* #ORM\Column(name="state", type="string", length=50, nullable=true)
*/
private $state;
/**
* #var string $zipcode
*
* #ORM\Column(name="zipcode", type="string", length=50, nullable=true)
*/
private $zipcode;
/**
* #var integer $countryId
*
* #ORM\Column(name="country_id", type="integer", nullable=true)
*/
private $countryId;
/**
* #var string $telephone
*
* #ORM\Column(name="telephone", type="string", length=25, nullable=true)
*/
private $telephone;
/**
* #var string $fax
*
* #ORM\Column(name="fax", type="string", length=25, nullable=true)
*/
private $fax;
/**
* #var integer $workplaceId
*
* #ORM\Column(name="workplace_id", type="integer", nullable=true)
*/
private $workplaceId;
/**
* #var integer $jobtypeId
*
* #ORM\Column(name="jobtype_id", type="integer", nullable=true)
*/
private $jobtypeId;
/**
* #var string $researchKeywords
*
* #ORM\Column(name="research_keywords", type="string", length=255, nullable=true)
*/
private $researchKeywords;
/**
* #var string $ip
*
* #ORM\Column(name="ip", type="string", length=15, nullable=true)
*/
private $ip;
/**
* #var boolean $status
*
* #ORM\Column(name="status", type="boolean", nullable=false)
*/
private $status;
/**
* #var boolean $active
*
* #ORM\Column(name="active", type="boolean", nullable=false)
*/
private $active;
/**
* #var bigint $dateRegistered
*
* #ORM\Column(name="date_registered", type="bigint", nullable=false)
*/
private $dateRegistered;
/**
* #var string $alertFrequency
*
* #ORM\Column(name="alert_frequency", type="string", length=10, nullable=true)
*/
private $alertFrequency;
/**
* #var datetime $alertLastSuccess
*
* #ORM\Column(name="alert_last_success", type="datetime", nullable=false)
*/
private $alertLastSuccess;
/**
* #var text $signature
*
* #ORM\Column(name="signature", type="text", nullable=true)
*/
private $signature;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set editorId
*
* #param integer $editorId
*/
public function setEditorId($editorId)
{
$this->editorId = $editorId;
}
/**
* Get editorId
*
* #return integer
*/
public function getEditorId()
{
return $this->editorId;
}
/**
* Set email
*
* #param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* #param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set titleId
*
* #param integer $titleId
*/
public function setTitleId($titleId)
{
$this->titleId = $titleId;
}
/**
* Get titleId
*
* #return integer
*/
public function getTitleId()
{
return $this->titleId;
}
/**
* Set firstname
*
* #param string $firstname
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}
/**
* Get firstname
*
* #return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* #param string $lastname
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
/**
* Get lastname
*
* #return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set department
*
* #param string $department
*/
public function setDepartment($department)
{
$this->department = $department;
}
/**
* Get department
*
* #return string
*/
public function getDepartment()
{
return $this->department;
}
/**
* Set organization
*
* #param string $organization
*/
public function setOrganization($organization)
{
$this->organization = $organization;
}
/**
* Get organization
*
* #return string
*/
public function getOrganization()
{
return $this->organization;
}
/**
* Set address1
*
* #param string $address1
*/
public function setAddress1($address1)
{
$this->address1 = $address1;
}
/**
* Get address1
*
* #return string
*/
public function getAddress1()
{
return $this->address1;
}
/**
* Set address2
*
* #param string $address2
*/
public function setAddress2($address2)
{
$this->address2 = $address2;
}
/**
* Get address2
*
* #return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* Set city
*
* #param string $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* Get city
*
* #return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set state
*
* #param string $state
*/
public function setState($state)
{
$this->state = $state;
}
/**
* Get state
*
* #return string
*/
public function getState()
{
return $this->state;
}
/**
* Set zipcode
*
* #param string $zipcode
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
}
/**
* Get zipcode
*
* #return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set countryId
*
* #param integer $countryId
*/
public function setCountryId($countryId)
{
$this->countryId = $countryId;
}
/**
* Get countryId
*
* #return integer
*/
public function getCountryId()
{
return $this->countryId;
}
/**
* Set telephone
*
* #param string $telephone
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
}
/**
* Get telephone
*
* #return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set fax
*
* #param string $fax
*/
public function setFax($fax)
{
$this->fax = $fax;
}
/**
* Get fax
*
* #return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set workplaceId
*
* #param integer $workplaceId
*/
public function setWorkplaceId($workplaceId)
{
$this->workplaceId = $workplaceId;
}
/**
* Get workplaceId
*
* #return integer
*/
public function getWorkplaceId()
{
return $this->workplaceId;
}
/**
* Set jobtypeId
*
* #param integer $jobtypeId
*/
public function setJobtypeId($jobtypeId)
{
$this->jobtypeId = $jobtypeId;
}
/**
* Get jobtypeId
*
* #return integer
*/
public function getJobtypeId()
{
return $this->jobtypeId;
}
/**
* Set researchKeywords
*
* #param string $researchKeywords
*/
public function setResearchKeywords($researchKeywords)
{
$this->researchKeywords = $researchKeywords;
}
/**
* Get researchKeywords
*
* #return string
*/
public function getResearchKeywords()
{
return $this->researchKeywords;
}
/**
* Set ip
*
* #param string $ip
*/
public function setIp($ip)
{
$this->ip = $ip;
}
/**
* Get ip
*
* #return string
*/
public function getIp()
{
return $this->ip;
}
/**
* Set status
*
* #param boolean $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* Get status
*
* #return boolean
*/
public function getStatus()
{
return $this->status;
}
/**
* Set active
*
* #param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* Get active
*
* #return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set dateRegistered
*
* #param bigint $dateRegistered
*/
public function setDateRegistered($dateRegistered)
{
$this->dateRegistered = $dateRegistered;
}
/**
* Get dateRegistered
*
* #return bigint
*/
public function getDateRegistered()
{
return $this->dateRegistered;
}
/**
* Set alertFrequency
*
* #param string $alertFrequency
*/
public function setAlertFrequency($alertFrequency)
{
$this->alertFrequency = $alertFrequency;
}
/**
* Get alertFrequency
*
* #return string
*/
public function getAlertFrequency()
{
return $this->alertFrequency;
}
/**
* Set alertLastSuccess
*
* #param datetime $alertLastSuccess
*/
public function setAlertLastSuccess($alertLastSuccess)
{
$this->alertLastSuccess = $alertLastSuccess;
}
/**
* Get alertLastSuccess
*
* #return datetime
*/
public function getAlertLastSuccess()
{
return $this->alertLastSuccess;
}
/**
* Set signature
*
* #param text $signature
*/
public function setSignature($signature)
{
$this->signature = $signature;
}
/**
* Get signature
*
* #return text
*/
public function getSignature()
{
return $this->signature;
}
}
Make sure the value you are using in the find method is the same as the defined primary key ( #ID ) in your entity.

Resources