新的doctrime ORM表字段创建器,但表示仍未映射

时间:2019-10-03 17:03:55

标签: php symfony doctrine-orm doctrine

我在我的“列表”实体中添加了一个新字段/列,该实体/名称是一个名为“ promoted”的布尔值,类似于已在数据库“ certified”中存在的布尔值,但是其行为完全相同。它不起作用.. mariadb db正确更新了包含布尔值的新行,但是当我尝试在部分查询中使用它或以某种形式将字段从0更新为1时,它不会更新,就像未映射一样,这是我的代码(不是全部)只是重要的部分是3个函数,每行有1000多个行:BaseListing.php

/**
 * Listing
 *
 * @CocoricoAssert\ListingConstraint()
 *
 * @ORM\MappedSuperclass
 */
abstract class BaseListing
{
    protected $price = 0;

    /**
     *
     * @ORM\Column(name="certified", type="boolean", nullable=true)
     *
     * @var boolean
     */
    protected $certified;

    /**
     *
     * @ORM\Column(name="min_duration", type="smallint", nullable=true)
     *
     * @var integer
     */

    /**
     *
     * @ORM\Column(name="promoted", type="boolean", nullable=true)
     * 
     * @var boolean
     */
    protected $promoted;


    /**
     * @return boolean
     */
    public function isCertified()
    {
        return $this->certified;
    }

    /**
     * @param boolean $certified
     */
    public function setCertified($certified)
    {
        $this->certified = $certified;
    }

    /**
     * @return boolean
     */
    public function isPromoted()
    {
        return $this->promoted;
    }

    /**
     * @param boolean $promoted
     */
    public function setPromoted($promoted)
    {
        $this->promoted = $promoted;
    }
}

这是AdminListing.php,用于生成管理面板的表单,以通过/关闭认证,并且如我希望打开/关闭(由于文件太大而被删除):

class ListingAdmin extends AbstractAdmin
{
    /** @inheritdoc */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('admin.listing.title')
            ->add(
                'status',
                ChoiceType::class,
                array(
                    'choices' => array_flip(Listing::$statusValues),
                    'placeholder' => 'admin.listing.status.label',
                    'translation_domain' => 'cocorico_listing',
                    'label' => 'admin.listing.status.label',
                )
            )
            ->add(
                'adminNotation',
                ChoiceType::class,
                array(
                    'choices' => array_combine(
                        range(0, 10, 0.5),
                        array_map(
                            function ($num) {
                                return number_format($num, 1);
                            },
                            range(0, 10, 0.5)
                        )
                    ),
                    'placeholder' => 'admin.listing.admin_notation.label',
                    'label' => 'admin.listing.admin_notation.label',
                    'required' => false,
                )
            )
            ->add(
                'certified',
                null,
                array(
                    'label' => 'admin.listing.certified.label',
                )
            )
            ->add(
                'promoted',
                CheckboxType::class,
                array(
                    'label' => 'admin.listing.promoted.label',
                    'required' => false,
                )
            )

这不起作用,因为我在ListingRepository中有一个使用“认证”的查询:

public function getFindSelectPart(QueryBuilder $queryBuilder)
    {
        $queryBuilder
            ->select("partial l.{id, price, averageRating, certified, createdAt, commentCount}")
            ->addSelect("partial t.{id, locale, slug, title, description}")
            ->addSelect("partial llcat.{id, listing, category}")
            ->addSelect("partial ca.{id, lft, lvl, rgt, root}")
            ->addSelect("partial cat.{id, locale, name}")
            ->addSelect("partial i.{id, name}")
            ->addSelect("partial u.{id, firstName}")
            ->addSelect("partial ln.{id, city, route, country}")
            ->addSelect("partial co.{id, lat, lng}")
            ->addSelect("partial ui.{id, name}")
            ->addSelect("'' AS DUMMY");//To maintain fields on same array level when extra fields are added

        return $queryBuilder;
    }

当我在部分查询中将提升晋升到认证之后时,它说: [语义错误]行0,第88行靠近partial.l错误:类Cocorico \ ListingBundle \ Entity \ Listing上没有名为“ promoted”的映射字段

除了我已完成与认证值完全相同的设置外,我还清除了缓存并更新了数据库方案。

这是我的Entity \ Listing.php:

?php

namespace Cocorico\ListingBundle\Entity;

use Cocorico\BookingBundle\Entity\Booking;
use Cocorico\ListingBundle\Model\BaseListing;
use Cocorico\ListingBundle\Model\ListingOptionInterface;
use Cocorico\ListingCategoryBundle\Entity\ListingListingCategory;
use Cocorico\ListingCharacteristicBundle\Entity\ListingListingCharacteristic;
use Cocorico\ListingDiscountBundle\Entity\ListingDiscount;
use Cocorico\ListingImageBundle\Entity\ListingImage;
use Cocorico\ListingLocationBundle\Entity\ListingLocation;
use Cocorico\MessageBundle\Entity\Thread;
use Cocorico\UserBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Symfony\Component\Validator\Constraints as Assert;


/**
 * Listing
 *
 * @ORM\Entity(repositoryClass="Cocorico\ListingBundle\Repository\ListingRepository")
 *
 * @ORM\Table(name="listing",indexes={
 *    @ORM\Index(name="created_at_l_idx", columns={"created_at"}),
 *    @ORM\Index(name="status_l_idx", columns={"status"}),
 *    @ORM\Index(name="price_idx", columns={"price"}),
 *    @ORM\Index(name="type_idx", columns={"type"}),
 *    @ORM\Index(name="min_duration_idx", columns={"min_duration"}),
 *    @ORM\Index(name="max_duration_idx", columns={"max_duration"}),
 *    @ORM\Index(name="average_rating_idx", columns={"average_rating"}),
 *    @ORM\Index(name="admin_notation_idx", columns={"admin_notation"}),
 *    @ORM\Index(name="platform_notation_idx", columns={"platform_notation"})
 *  })
 */
class Listing extends BaseListing
{
    use ORMBehaviors\Timestampable\Timestampable;
    use ORMBehaviors\Translatable\Translatable;

    use \Cocorico\ListingSearchAdvancedBundle\Model\ListingSearchableTrait;
//    use \Cocorico\ListingCategoryFieldBundle\Model\ListingCategoryFieldableTrait;
//    use \Cocorico\DeliveryBundle\Model\ListingDeliverableTrait;
//    use \Cocorico\ListingDepositBundle\Model\ListingDepositableTrait;
//    use \Cocorico\ListingSessionBundle\Model\ListingSessionableTrait;

//    use \Cocorico\ServiceBundle\Model\ListingTrait;
//    use \Cocorico\ListingVideoBundle\Model\ListingVideoTrait;
//    use \Cocorico\CarrierBundle\Model\ListingCarrierableTrait;

    /**
     * @ORM\Id
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class="Cocorico\CoreBundle\Model\CustomIdGenerator")
     *
     * @var integer
     */
    protected $id;

    /**
     * @Assert\NotBlank(message="assert.not_blank")
     *
     * @ORM\ManyToOne(targetEntity="Cocorico\UserBundle\Entity\User", inversedBy="listings", cascade={"persist"})
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
     *
     * @var User
     */
    protected $user;
/**
     * @ORM\OneToOne(targetEntity="Cocorico\ListingLocationBundle\Entity\ListingLocation", inversedBy="listing", cas\
cade={"persist", "remove"}, orphanRemoval=true)
     * @ORM\JoinColumn(name="location_id", referencedColumnName="id", onDelete="CASCADE")
     *
     * @var ListingLocation
     **/
    protected $location;

    /**
     * @ORM\OneToMany(targetEntity="Cocorico\ListingCategoryBundle\Entity\ListingListingCategory", mappedBy="listing\
", cascade={"persist", "remove"}, orphanRemoval=true)//, fetch="EAGER"
     *
     */
    protected $listingListingCategories;

    /**
     * For Asserts @see \Cocorico\ListingBundle\Validator\Constraints\ListingValidator
     *
     * @ORM\OneToMany(targetEntity="Cocorico\ListingImageBundle\Entity\ListingImage", mappedBy="listing", cascade={"\
persist", "remove"}, orphanRemoval=true)
     * @ORM\OrderBy({"position" = "asc"})
     */
    protected $images;

    /**
     * @ORM\OneToMany(targetEntity="Cocorico\ListingCharacteristicBundle\Entity\ListingListingCharacteristic", mappe\
dBy="listing", cascade={"persist", "remove"}, orphanRemoval=true) //, fetch="EAGER"
     *
     */
    protected $listingListingCharacteristics;

    /**
     *
     * @ORM\OneToMany(targetEntity="Cocorico\ListingDiscountBundle\Entity\ListingDiscount", mappedBy="listing", casc\
ade={"persist", "remove"}, orphanRemoval=true)
     * @ORM\OrderBy({"fromQuantity" = "asc"})
     */
    protected $discounts;


    /**
     * @ORM\OneToMany(targetEntity="Cocorico\BookingBundle\Entity\Booking", mappedBy="listing", cascade={"persist", \
"remove"}, orphanRemoval=true)
     * @ORM\OrderBy({"createdAt" = "desc"})
     */
    protected $bookings;
/**
     * @ORM\OneToMany(targetEntity="Cocorico\MessageBundle\Entity\Thread", mappedBy="listing", cascade={"remove"}, o\
rphanRemoval=true)
     * @ORM\OrderBy({"createdAt" = "desc"})
     */
    protected $threads;

    /**
     *
     * @ORM\OneToMany(targetEntity="Cocorico\ListingBundle\Model\ListingOptionInterface", mappedBy="listing", cascad\
e={"persist", "remove"}, orphanRemoval=true)
     */
    protected $options;


    public function __construct()
    {
        $this->images = new ArrayCollection();
        $this->listingListingCharacteristics = new ArrayCollection();
        $this->listingListingCategories = new ArrayCollection();
        $this->discounts = new ArrayCollection();
        $this->bookings = new ArrayCollection();
        $this->threads = new ArrayCollection();
        $this->options = new ArrayCollection();
    }


    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Add characteristics
     *
     * @param  ListingListingCharacteristic $listingListingCharacteristic
     * @return Listing
     */
    public function addListingListingCharacteristic(ListingListingCharacteristic $listingListingCharacteristic)
    {
        $this->listingListingCharacteristics[] = $listingListingCharacteristic;

        return $this;
    }
 /**
     * Remove characteristics
     *
     * @param ListingListingCharacteristic $listingListingCharacteristic
     */
    public function removeListingListingCharacteristic(ListingListingCharacteristic $listingListingCharacteristic)
    {
        $this->listingListingCharacteristics->removeElement($listingListingCharacteristic);
        $listingListingCharacteristic->setListing(null);
    }

    /**
     * Get characteristics
     *
     * @return \Doctrine\Common\Collections\Collection|ListingListingCharacteristic[]
     */
    public function getListingListingCharacteristics()
    {
        return $this->listingListingCharacteristics;
    }

 /**
     * Get characteristics ordered by Group and Characteristic
     *
     * @return ArrayCollection
     */
    public function getListingListingCharacteristicsOrderedByGroup()
    {
        $iterator = $this->listingListingCharacteristics->getIterator();
        $iterator->uasort(
            function ($a, $b) {
                /**
                 * @var ListingListingCharacteristic $a
                 * @var ListingListingCharacteristic $b
                 */
                $groupPosA = $a->getListingCharacteristic()->getListingCharacteristicGroup()->getPosition();
                $groupPosB = $b->getListingCharacteristic()->getListingCharacteristicGroup()->getPosition();

                $characteristicPosA = $a->getListingCharacteristic()->getPosition();
                $characteristicPosB = $b->getListingCharacteristic()->getPosition();
                if ($groupPosA == $groupPosB) {
                    if ($characteristicPosA == $characteristicPosB) {
                        return 0;
                    }

                    return ($characteristicPosA < $characteristicPosB) ? -1 : 1;
                }

                return ($groupPosA < $groupPosB) ? -1 : 1;
            }
        );

        return new ArrayCollection(iterator_to_array($iterator));
    }
 /**
     * Add characteristics
     *
     * @param  ListingListingCharacteristic $listingListingCharacteristic
     * @return Listing
     */
    public function addListingListingCharacteristicsOrderedByGroup(
        ListingListingCharacteristic $listingListingCharacteristic
    ) {
        return $this->addListingListingCharacteristic($listingListingCharacteristic);
    }


    /**
     * Remove characteristics
     *
     * @param ListingListingCharacteristic $listingListingCharacteristic
     */
    public function removeListingListingCharacteristicsOrderedByGroup(
        ListingListingCharacteristic $listingListingCharacteristic
    ) {
        $this->removeListingListingCharacteristic($listingListingCharacteristic);
    }
 /**
     * Add category
     *
     * @param  ListingListingCategory $listingListingCategory
     * @return Listing
     */
    public function addListingListingCategory(ListingListingCategory $listingListingCategory)
    {
        $listingListingCategory->setListing($this);
        $this->listingListingCategories[] = $listingListingCategory;

        return $this;
    }
    /**
     * Remove category
     *
     * @param ListingListingCategory $listingListingCategory
     */
    public function removeListingListingCategory(ListingListingCategory $listingListingCategory)
    {
//        foreach ($listingListingCategory->getValues() as $value) {
//            $listingListingCategory->removeValue($value);
//        }

        $this->listingListingCategories->removeElement($listingListingCategory);
    }
/**
     * Get categories
     *
     * @return \Doctrine\Common\Collections\Collection|ListingListingCategory[]
     */
    public function getListingListingCategories()
    {
        return $this->listingListingCategories;
    }


    /**
     * Set user
     *
     * @param  \Cocorico\UserBundle\Entity\User $user
     * @return Listing
     */
    public function setUser(User $user = null)
    {
        $this->user = $user;

        return $this;
    }
 /**
     * Get user
     *
     * @return \Cocorico\UserBundle\Entity\User
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Add images
     *
     * @param  ListingImage $image
     * @return Listing
     */
    public function addImage(ListingImage $image)
    {
        $image->setListing($this); //Because the owning side of this relation is listing image
        $this->images[] = $image;

        return $this;
    }

    /**
     * Remove images
     *
     * @param ListingImage $image
     */
    public function removeImage(ListingImage $image)
    {
        $this->images->removeElement($image);
        $image->setListing(null);
    }

    /**
     * Get images
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getImages()
    {
        return $this->images;
    }

    /**
     * Set location
     *
     * @param  ListingLocation $location
     * @return Listing
     */
    public function setLocation(ListingLocation $location = null)
    {
        $this->location = $location;
        //Needed to persist listing_id on listing_location table when inserting a new listing embedding a listing location form
        $this->location->setListing($this);
    }
/**
     * Get location
     *
     * @return ListingLocation
     */
    public function getLocation()
    {
        return $this->location;
    }


    /**
     * Add discount
     *
     * @param  ListingDiscount $discount
     * @return Listing
     */
    public function addDiscount(ListingDiscount $discount)
    {
        $discount->setListing($this);
        $this->discounts[] = $discount;

        return $this;
    }

    /**
     * Remove discount
     *
     * @param ListingDiscount $discount
     */
    public function removeDiscount(ListingDiscount $discount)
    {
        $this->discounts->removeElement($discount);
        $discount->setListing(null);
    }

    /**
     * Get discounts
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getDiscounts()
    {
        return $this->discounts;
    }

    /**
     * @param ArrayCollection|ListingDiscount[] $discounts
     */
    public function setDiscounts(ArrayCollection $discounts)
    {
        foreach ($discounts as $discount) {
            $discount->setListing($this);
        }

        $this->discounts = $discounts;
    }
/**
     * @return \Doctrine\Common\Collections\Collection|Booking[]
     */
    public function getBookings()
    {
        return $this->bookings;
    }

    /**
     * @param ArrayCollection|Booking[] $bookings
     */
    public function setBookings(ArrayCollection $bookings)
    {
        foreach ($bookings as $booking) {
            $booking->setListing($this);
        }

        $this->bookings = $bookings;
    }

    /**
     * Add booking
     *
     * @param Booking $booking
     *
     * @return Listing
     */
    public function addBooking(Booking $booking)
    {
        $this->bookings[] = $booking;

        return $this;
    }

    /**
     * Remove booking
     *
     * @param Booking $booking
     */
    public function removeBooking(Booking $booking)
    {
        $this->bookings->removeElement($booking);
    }

    /**
     * @return mixed
     */
    public function getThreads()
    {
        return $this->threads;
    }

    /**
     * @param ArrayCollection|Thread[] $threads
     */
    public function setThreads(ArrayCollection $threads)
    {
foreach ($threads as $thread) {
            $thread->setListing($this);
        }

        $this->threads = $threads;
    }

    /**
     * Add thread
     *
     * @param Thread $thread
     *
     * @return Listing
     */
    public function addThread(Thread $thread)
    {
        $this->threads[] = $thread;

        return $this;
    }

    /**
     * Remove thread
     *
     * @param Thread $thread
     */
    public function removeThread(Thread $thread)
    {
        $this->threads->removeElement($thread);
    }

    /**
     * Add ListingOption
     *
     * @param  ListingOptionInterface $option
     * @return Listing
     */
    public function addOption($option)
    {
        $option->setListing($this);
        $this->options[] = $option;

        return $this;
    }

    /**
     * Remove ListingOption
     *
     * @param ListingOptionInterface $option
     */
    public function removeOption($option)
    {
        $this->options->removeElement($option);
    }foreach ($threads as $thread) {
            $thread->setListing($this);
        }

        $this->threads = $threads;
    }

    /**
     * Add thread
     *
     * @param Thread $thread
     *
     * @return Listing
     */
    public function addThread(Thread $thread)
    {
        $this->threads[] = $thread;

        return $this;
    }

    /**
     * Remove thread
     *
     * @param Thread $thread
     */
    public function removeThread(Thread $thread)
    {
        $this->threads->removeElement($thread);
    }

    /**
     * Add ListingOption
     *
     * @param  ListingOptionInterface $option
     * @return Listing
     */
    public function addOption($option)
    {
        $option->setListing($this);
        $this->options[] = $option;

        return $this;
    }

    /**
     * Remove ListingOption
     *
     * @param ListingOptionInterface $option
     */
    public function removeOption($option)
    {
        $this->options->removeElement($option);
    }
/**
     * Get ListingOptions
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * @param ArrayCollection $options
     * @return $this
     */
    public function setOptions(ArrayCollection $options)
    {
        foreach ($options as $option) {
            $option->setListing($this);
        }

        $this->options = $options;

        return $this;
    }


    /**
     * @param int  $minImages
     * @param bool $strict
     *
     * @return array
     */
    public function getCompletionInformations($minImages, $strict = true)
    {
        $characteristic = 0;
        foreach ($this->getListingListingCharacteristics() as $characteristics) {
            if ($characteristics->getListingCharacteristicValue()) {
                $characteristic = 1;
            }
        }

        return array(
            "title" => $this->getTitle() ? 1 : 0,
            "description" => (
                ($strict && $this->getDescription()) ||
                (!$strict && strlen($this->getDescription()) > 250)
            ) ? 1 : 0,
            "price" => $this->getPrice() ? 1 : 0,
            "image" => (
                ($strict && count($this->getImages()) >= $minImages) ||
                (!$strict && count($this->getImages()) > $minImages)
            ) ? 1 : 0,
            "characteristic" => $characteristic,
        );
    }
public function getTitle()
    {   
        return (string)$this->translate()->getTitle();
    }

    public function getSlug()
    {   
        return (string)$this->translate()->getSlug();
    }

    public function __toString()
    {
        return (string)$this->getTitle();
    }
    /**
     * To add impersonating link into admin :
     *
     * @return User
     */
    public function getImpersonating()
    {
        return $this->getUser();
    }
}

0 个答案:

没有答案