gpt4 book ai didi

mysql - 学说 2 多对多翻译

转载 作者:行者123 更新时间:2023-11-29 00:28:05 26 4
gpt4 key购买 nike

我对原则 2 有疑问。我有以下数据库表:因此,Doctrine 生成从站点的桌面设置中检索数据的实体,但我需要从 desk_settings 表中检索所有设置并使用 desk_id 从 desk_settings_values 表中覆盖其值

数据库图像 -> https://docs.google.com/file/d/0B7rOFTJGfJwTWEQ3bXZFU1hXZlU/edit?usp=sharing

用脚本生成的 Doctrine 实体:

/** * Desk * * @ORM\Table(name="desk") * @ORM\Entity */class Desk{    /**     * @var integer     *     * @ORM\Column(name="id", type="integer", nullable=false)     * @ORM\Id     * @ORM\GeneratedValue(strategy="IDENTITY")     */    private $id;    /**     * @var string     *     * @ORM\Column(name="code", type="string", length=100, nullable=false)     */    private $code;    /**     * @var string     *     * @ORM\Column(name="description", type="string", length=255, nullable=false)     */    private $description;    /**     * @var \DateTime     *     * @ORM\Column(name="created", type="datetime", nullable=false)     */    private $created;    /**     * @var \Doctrine\Common\Collections\Collection     *     * @ORM\ManyToMany(targetEntity="PayBox\Entity\DeskSettings", mappedBy="desk")     */    private $deskSettings;}
use Doctrine\ORM\Mapping as ORM;/** * DeskSettings * * @ORM\Table(name="desk_settings") * @ORM\Entity */class DeskSettings{    /**     * @var integer     *     * @ORM\Column(name="id", type="integer", nullable=false)     * @ORM\Id     * @ORM\GeneratedValue(strategy="IDENTITY")     */    private $id;    /**     * @var string     *     * @ORM\Column(name="setting_key", type="string", length=100, nullable=false)     */    private $settingKey;    /**     * @var string     *     * @ORM\Column(name="setting_value", type="string", length=255, nullable=false)     */    private $settingValue;    /**     * @var \DateTime     *     * @ORM\Column(name="created", type="datetime", nullable=false)     */    private $created;    /**     * @var \Doctrine\Common\Collections\Collection     *     * @ORM\ManyToMany(targetEntity="PayBox\Entity\Desk", inversedBy="deskSettings")     * @ORM\JoinTable(name="desk_settings_values",     *   joinColumns={     *     @ORM\JoinColumn(name="desk_settings_id", referencedColumnName="id")     *   },     *   inverseJoinColumns={     *     @ORM\JoinColumn(name="desk_id", referencedColumnName="id")     *   }     * )     */    private $desk; }

最佳答案

来自 Doctrine 文档:

Why are many-to-many associations less common? Because frequently you want to associate additional attributes with an association, in which case you introduce an association class. Consequently, the direct many-to-many association disappears and is replaced by one-to-many/many-to-one associations between the 3 participating classes.

您需要将类结构更改为一对多/多对一。 See this blog .

关于mysql - 学说 2 多对多翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18036190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com