duanfang2708 2012-08-08 07:23
浏览 98
已采纳

使用@OneToOne的语句 - Doctrine2

I have a table with Products and another table with Notes. Each product can have or not some notes. I need only the notes to know to which product they are reffered, but the product not to know about its notes. I think that this should be my code:

namespace EM\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use EM\MyBundle\Entity\Productss;

/**
 * @ORM\Entity
 * @ORM\Table(name="notes")
 */
class Notess
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @OneToOne(targetEntity="Productss")
 * @JoinColumn(name="products_id", referencedColumnName="id")
 **/
private $products; 
//... 
}

namespace EM\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="domains")
 */
class Domains
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;
// ...
}

but it gives an error: [Doctrine\Common\Annotations\AnnotationException]

[Semantical Error] The annotation "@OneToOne" in property EM\MyBundle\ Entity\Notes::$products was never imported. Did you maybe forget to add a "use " statement for this annotation?

Can you please help me to fix this?

  • 写回答

1条回答 默认 最新

  • dougu3290 2012-08-08 07:29
    关注

    I think you were meant to use @ORM\OneToOne instead...

    /**
     * @ORM\OneToOne(targetEntity="Productss")
     * @ORM\JoinColumn(name="products_id", referencedColumnName="id")
     */
    private $products; 
    //... 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀