Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony 2 switching between types of entity schema description (doctrine)

I develop store using SyliusSandbox bundle. Sylius uses xml files to store ORM schema for entities.

I've copied its xml definitions to my Bundle and use it there.

But for my own entities, I'd like to use annotations. So, basically I need to mix two types of definitions in one bundle. If I try to persist an entity which is using annotations, I get an error that xml file for this entity was not found:

No mapping file found named 'ShopBundle\Resources\config\doctrine/ProductLocalized.orm.xml' for class '\ShopBundle\Entity\ProductLocalized'.

My entity looks like this:

<?php

namespace Pixeljets\ShopBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Pixeljets\ShopBundle\Entity\ProductLocalized
 *
 * @ORM\Table(name="product_localized")
 * @ORM\Entity
 */
class ProductLocalized
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="localized")
     * @ORM\JoinColumn(name="product_id", referencedColumnName="id")
     */
    protected $product;



    /**
     * @var integer $product_id
     *
     * @ORM\Column(name="product_id", type="integer")
     */
    private $product_id;

    /**
     * @var string $title
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title;

    /**
     * @var string $url
     *
     * @ORM\Column(name="url", type="string", length=255)
     */
    private $url;

    /**
     * @var string $keywords
     *
     * @ORM\Column(name="keywords", type="string", length=255, nullable=true)
     */
    private $keywords;

    /**
     * @var string $description
     *
     * @ORM\Column(name="description", type="string", length=255, nullable=true)
     */
    private $description;

    /**
     * @var string $body
     *
     * @ORM\Column(name="body", type="text", nullable=true)
     */
    private $body;

    /**
     * @var boolean $published
     *
     * @ORM\Column(name="published", type="boolean")
     */
    private $published;

    /**
     * @var string $lang
     *
     * @ORM\Column(name="lang", type="string", length=2)
     */
    private $lang;


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

    /**
     * Set product_id
     *
     * @param integer $productId
     * @return ProductLocalized
     */
    public function setProductId($productId)
    {
        $this->product_id = $productId;

        return $this;
    }

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

    /**
     * Set title
     *
     * @param string $title
     * @return ProductLocalized
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set url
     *
     * @param string $url
     * @return ProductLocalized
     */
    public function setUrl($url)
    {
        $this->url = $url;

        return $this;
    }

    /**
     * Get url
     *
     * @return string 
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * Set keywords
     *
     * @param string $keywords
     * @return ProductLocalized
     */
    public function setKeywords($keywords)
    {
        $this->keywords = $keywords;

        return $this;
    }

    /**
     * Get keywords
     *
     * @return string 
     */
    public function getKeywords()
    {
        return $this->keywords;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return ProductLocalized
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set body
     *
     * @param string $body
     * @return ProductLocalized
     */
    public function setBody($body)
    {
        $this->body = $body;

        return $this;
    }

    /**
     * Get body
     *
     * @return string 
     */
    public function getBody()
    {
        return $this->body;
    }

    /**
     * Set published
     *
     * @param boolean $published
     * @return ProductLocalized
     */
    public function setPublished($published)
    {
        $this->published = $published;

        return $this;
    }

    /**
     * Get published
     *
     * @return boolean 
     */
    public function getPublished()
    {
        return $this->published;
    }

    /**
     * Set lang
     *
     * @param string $lang
     * @return ProductLocalized
     */
    public function setLang($lang)
    {
        $this->lang = $lang;

        return $this;
    }

    /**
     * Get lang
     *
     * @return string 
     */
    public function getLang()
    {
        return $this->lang;
    }

    /**
     * Set product
     *
     * @param Pixeljets\ShopBundle\Entity\Product $product
     * @return ProductLocalized
     */
    public function setProduct(\Pixeljets\ShopBundle\Entity\Product $product = null)
    {
        $this->product = $product;

        return $this;
    }

    /**
     * Get product
     *
     * @return Pixeljets\ShopBundle\Entity\Product 
     */
    public function getProduct()
    {
        return $this->product;
    }
}
?>

How can I 'tell' symfony to use annotation approach for schema?


1 Answers

You cannot mix metadata formats inside of a bundle:

From: http://symfony.com/doc/current/book/doctrine.html

A bundle can accept only one metadata definition format. For example, it's not 
possible to mix YAML metadata definitions with annotated PHP entity class definitions.

You will need to use two bundles or stick with one format.

like image 50
Cerad Avatar answered Dec 03 '25 13:12

Cerad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!