duanlao6573 2013-10-09 13:07
浏览 61

学说中的一对多与多对一关系

I have 2 Tables

  1. Users
  2. Messages

And the Structure of Tables:

Users:

enter image description here

Messages:

enter image description here

Now see there are number of users in Users Table and their messages are stored in Messages table identifying by sender_id and receiver_id

How can I make One-To-Many and Many To One Relationship between these two tables or create this SQL Schema using Doctrine/Annotations?

  • 写回答

1条回答 默认 最新

  • drnbotxo449747 2013-10-09 13:13
    关注

    Something like that:

    /**
     * @ORM\Entity
     * @ORM\Table(name="messages")
     */
    class Comment
    {
        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;
    
        /**
         * @ORM\Column(type="string", length=5000, nullable=true)
         */
        protected $text;
    
    
        /**
         * Author of the comment
         *
         * @ORM\ManyToOne(targetEntity="Acme\UserBundle\Entity\User")
         * @var User
         */
        protected $sender;
    
       /**
         * 
         *
         * @ORM\ManyToOne(targetEntity="Acme\UserBundle\Entity\User")
         * @var User
         */
        protected $reciever;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)