I have a problem : I get a repository in a service and I do a findAll on it, problem: I get an empty array (while my database is not). So I guess I'm doing something wrong, I hope you can enlighten me.
<?php
/**
* Created by PhpStorm.
* User: thocou
* Date: 07/03/19
* Time: 15:05
*/
namespace App\Service;
use App\Entity\RentRelease;
use App\Repository\PropertyRepository;
use Doctrine\Common\Persistence\ObjectManager;
class RentReleaseInsertion
{
private $propertyRepository;
private $manager;
public function __construct(PropertyRepository $propertyRepository, ObjectManager $manager)
{
$this->propertyRepository = $propertyRepository;
$this->manager = $manager;
}
public function settingRentReleaseValues()
{
$property = $this->propertyRepository->findAll();
dd($property);
foreach ($property as $prop) {
$lessees = $prop->getLessees();
foreach ($lessees as $lessee) {
$rentRelease = new RentRelease();
$amount = $prop->getRentExcludingCharges() + $prop->getCharges();
$rentRelease->setRentRelease($lessee);
$rentRelease->setAmount($amount);
$rentRelease->setStatus('Paiement en attente');
$this->manager->persist($rentRelease);
$this->manager->flush();
}
}
}
}
the repository is here :
<?php
namespace App\Repository;
use App\Entity\Property;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* @method Property|null find($id, $lockMode = null, $lockVersion = null)
* @method Property|null findOneBy(array $criteria, array $orderBy = null)
* @method Property[] findAll()
* @method Property[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PropertyRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Property::class);
}
}
To be honnest I don't really understand where is the problem from, even though I suspect it's a very small problem.
EDIT :
here is my entity (i don't show you getter setter because it's +500 lines but they have been generated):
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping\JoinColumn;
/**
* @ORM\Entity(repositoryClass="App\Repository\PropertyRepository")
*/
class Property
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Assert\Type("integer")
* @var int
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Choice({"Appartement", "Maison", "Garage", "Bureau", "Château", "Commerce"})
* @var string
*/
private $propertyCategory;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Type("string")
* @var string
*/
private $uniqueName;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Type("string")
* @var string
*/
private $address;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Type("string")
* @var string
*/
private $city;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
* @Assert\Type("integer")
* @Assert\Length(min = 5, minMessage = "Ce champ doit contenir 5 chiffres")
* @Assert\Length(max = 5, maxMessage = "Ce champ doit contenir 5 chiffres")
* @var int
*/
private $zipCode;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Country
* @var string
*/
private $country;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
* @Assert\Type("integer")
* @var string
*/
private $surfaceInSquareMeter;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
* @Assert\Type("integer")
* @var int
*/
private $numberOfPiece;
/**
* @ORM\Column(type="text", nullable=true)
* @Assert\Type("string")
* @var string
*/
private $description;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Choice({"Meublé", "Non meublé"})
* @var string
*/
private $rentalCategory;
/**
* @ORM\Column(type="float")
* @Assert\NotBlank
* @Assert\Type("float")
* @var float
*/
private $rentExcludingCharges;
/**
* @ORM\Column(type="float")
* @Assert\NotBlank
* @Assert\Type("float")
* @var float
*/
private $charges;
/**
* @ORM\Column(type="float")
* @Assert\NotBlank
* @Assert\Type("float")
* @var float
*/
private $purchasePrice;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="properties")
* @JoinColumn(name="user_property_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $userProperty;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Equipment", mappedBy="equipment")
*/
private $equipment;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Lessee", mappedBy="lessee")
*/
private $lessees;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\File(
* maxSize = "2000k",
* mimeTypes = {"application/pdf", "application/x-pdf"},
* mimeTypesMessage = "Choisisez un fichier PDF"
* )
*/
private $pdfFile;