0

I have an entity that contains a OneToOne relationship with another entity:

/**
 * @ORM\Entity
 * @ORM\Table(name="tb_promocao")
 */
class Promocao {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $codigo;

       /**
     * @ORM\OneToOne(targetEntity="Application\Model\Produto\Produto")
     * @ORM\JoinColumn(name="cod_produto", referencedColumnName="codigo")
     */
    private $produto;
}

/**
 * @ORM\Entity
 * @ORM\Table(name="tb_produto")
 */
class Produto {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $codigo;

        (...)

}

The problem is that when I try to give a fetch entity in Promocao the property $produto is not correctly populated with the Produto entity.

The Produto entity is not properly mapped on the property that receives the relationship.

Object of: EntityProxy__CG__\Application\Model\Produto\Produto

1
  • 1
    Try running the schema-check ./vendor/bin/doctrine-module orm:validate-schema
    – Sam
    Dec 23, 2012 at 11:14

1 Answer 1

1

This is normal operation. Your joined model is lazy load so while you don't call it, you will only have a proxy.

You can modify the type of loading joined model setting it to EAGER mode :

@ORM\OneToOne(targetEntity="Application\Model\Produto\Produto")
@ORM\JoinColumn(name="cod_produto", referencedColumnName="codigo", **fetch='EAGER'**)

But it's not really recommanded here except if you need this joined data everytimes.

Check Doctrine documentation, there are a lot of precisions about this.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.