duandu9260 2013-04-02 11:35
浏览 23
已采纳

Doctrine多个复合外键

I am trying to construct an object with two composite foreign keys pointing out to the same object, but they seem to have the same data, like doing the join only on one column, product_id.

class PostpaidProduct extends Product {
    /**
     * @ManyToOne(targetEntity="Bundle", fetch="EAGER", cascade={"persist"})
     * @JoinColumn(name="bundle_voice_id", referencedColumnName="id")
     */
    private $bundleVoice;

    /**
     * @ManyToOne(targetEntity="Bundle", fetch="EAGER", cascade={"persist"})
     * @JoinColumn(name="bundle_data_id", referencedColumnName="id")
     */
    private $bundleData;

    /**
     * @OneToMany(targetEntity="BundlePromo", mappedBy="product", fetch="EAGER", cascade={"persist"})
     * @JoinColumns({
     *   @JoinColumn(name="id", referencedColumnName="product_id"),
     *   @JoinColumn(name="bundle_voice_id", referencedColumnName="bundle_id")
     * })
     */
    private $bundleVoicePromos;

    /**
     * @OneToMany(targetEntity="BundlePromo", mappedBy="product", fetch="EAGER", cascade={"persist"})
     * @JoinColumns({
     *   @JoinColumn(name="id", referencedColumnName="product_id"),
     *   @JoinColumn(name="bundle_data_id", referencedColumnName="bundle_id")
     * })
     */
    private $bundleDataPromos;

}

What would be wrong with my mapping? Is it possible to have composite foreign keys but without being primary keys?

  • 写回答

1条回答 默认 最新

  • dongshan9338 2013-04-03 09:37
    关注

    I have talked to one of the developers of Doctrine and he said that the @JoinColumns field in @OneToMany relationships is ignored. The alternative would be having just one foreign key and to use matching criterias in an entity method, filtering for the entries needed based on the other key. Another solution would be having repository methods specific for getting these values.

    Also, in OneToMany relationships eager fetching does not work, so it does separate queries for all children. So if you have a product with multiple prices, when fetching a product it will do separate queries for fetching the prices.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法