SYMFONY4 FINDALL在服务中返回空数组



我有问题:我在服务中获得了一个存储库,并且在其中进行了一个发现,问题:我得到一个空数组(而数据库不是)。所以我想我做错了什么,希望你能启发我。

<?php
/**
 * Created by PhpStorm.
 * User: thocou
 * Date: 07/03/19
 * Time: 15:05
 */
namespace AppService;
use AppEntityRentRelease;
use AppRepositoryPropertyRepository;
use DoctrineCommonPersistenceObjectManager;
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();
        }
    }
}
}

存储库在这里:

<?php
namespace AppRepository;
use AppEntityProperty;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
use SymfonyBridgeDoctrineRegistryInterface;
/**
 * @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);
}
}

要成为honnest,我不太了解问题在哪里,即使我怀疑这是一个很小的问题。

编辑:

这是我的实体(我不向您显示Getter Setter,因为它是 500行,但已生成):

<?php
namespace AppEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use SymfonyComponentValidatorConstraints as Assert;
use DoctrineORMMappingJoinColumn;
/**
 * @ORMEntity(repositoryClass="AppRepositoryPropertyRepository")
 */
class Property
{
/**
 * @ORMId()
 * @ORMGeneratedValue()
 * @ORMColumn(type="integer")
 * @AssertType("integer")
 * @var int
 */
private $id;
/**
 * @ORMColumn(type="string", length=255)
 * @AssertNotBlank
 * @AssertChoice({"Appartement", "Maison", "Garage", "Bureau", "Château", "Commerce"})
 * @var string
 */
private $propertyCategory;
/**
 * @ORMColumn(type="string", length=255)
 * @AssertNotBlank
 * @AssertType("string")
 * @var string
 */
private $uniqueName;
/**
 * @ORMColumn(type="string", length=255)
 * @AssertNotBlank
 * @AssertType("string")
 * @var string
 */
private $address;
/**
 * @ORMColumn(type="string", length=255)
 * @AssertNotBlank
 * @AssertType("string")
 * @var string
 */
private $city;
/**
 * @ORMColumn(type="integer")
 * @AssertNotBlank
 * @AssertType("integer")
 * @AssertLength(min = 5, minMessage = "Ce champ doit contenir 5 chiffres")
 * @AssertLength(max = 5, maxMessage = "Ce champ doit contenir 5 chiffres")
 * @var int
 */
private $zipCode;
/**
 * @ORMColumn(type="string", length=255)
 * @AssertNotBlank
 * @AssertCountry
 * @var string
 */
private $country;
/**
 * @ORMColumn(type="integer")
 * @AssertNotBlank
 * @AssertType("integer")
 * @var string
 */
private $surfaceInSquareMeter;
/**
 * @ORMColumn(type="integer")
 * @AssertNotBlank
 * @AssertType("integer")
 * @var int
 */
private $numberOfPiece;
/**
 * @ORMColumn(type="text", nullable=true)
 * @AssertType("string")
 * @var string
 */
private $description;
/**
 * @ORMColumn(type="string", length=255)
 * @AssertNotBlank
 * @AssertChoice({"Meublé", "Non meublé"})
 * @var string
 */
private $rentalCategory;
/**
 * @ORMColumn(type="float")
 * @AssertNotBlank
 * @AssertType("float")
 * @var float
 */
private $rentExcludingCharges;
/**
 * @ORMColumn(type="float")
 * @AssertNotBlank
 * @AssertType("float")
 * @var float
 */
private $charges;
/**
 * @ORMColumn(type="float")
 * @AssertNotBlank
 * @AssertType("float")
 * @var float
 */
private $purchasePrice;
/**
 * @ORMManyToOne(targetEntity="AppEntityUser", inversedBy="properties")
 * @JoinColumn(name="user_property_id", referencedColumnName="id", onDelete="CASCADE")
 */
private $userProperty;
/**
 * @ORMManyToMany(targetEntity="AppEntityEquipment", mappedBy="equipment")
 */
private $equipment;
/**
 * @ORMManyToMany(targetEntity="AppEntityLessee", mappedBy="lessee")
 */
private $lessees;
/**
 * @ORMColumn(type="string", length=255, nullable=true)
 * @AssertFile(
 *     maxSize = "2000k",
 *     mimeTypes = {"application/pdf", "application/x-pdf"},
 *     mimeTypesMessage = "Choisisez un fichier PDF"
 * )
 */
private $pdfFile;

您是否检查了您的实体并验证此标头是否存在:


/**
 * @ORMEntity(repositoryClass="AppRepositoryPropertyRepository")
 */
class Property
{
...

相关内容

  • 没有找到相关文章

最新更新