学说多重复合外键 [英] Doctrine multiple composite foreign key

查看:103
本文介绍了学说多重复合外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用两个复合外键指向同一个对象来构造一个对象,但是它们似乎具有相同的数据,就像在一个列上的一个列进行连接,product_id。

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?

推荐答案

我已经和其中一个Doctrine的开发者,他表示@OneToMany关系中的@JoinColumns字段被忽略。替代方案只有一个外键,并且在实体方法中使用匹配标准,基于另一个键过滤所需的条目。另一个解决方案是具有专门用于获取这些值的存储库方法。

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.

另外,在OneToMany关系中,渴望提取不起作用,因此对所有子项都执行单独的查询。所以如果你有一个产品有多个价格,当提取一个产品时,它将单独查询价格。

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.

这篇关于学说多重复合外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆