douaikuai2715 2015-08-27 15:45
浏览 62

获取Doctrine findAll()以包含链接表中的关联

Background

I have a Discipline and a Playlist class.

  • A discipline can have zero to many playlists

  • A playlist can only be associated with one discipline

In my Controller, I have

$repository = $this->getDoctrine()
    ->getRepository('NodeBundle:Discipline');
$disciplines = $repository->findAll();

My discipline and playlist tables are pretty straightforward, but then there's a discipline_playlist link table, with id, discipline_id (FK), and playlist_id (FK).

Problem

What I'd like is for Doctrine to give me the Discipline objects, complete with an Array/Collection of Playlist objects.

Can this be achieved using Doctrine alone, or do I need to fetch the Playlists separately, and link them together in my controller (PHP)?

  • 写回答

1条回答 默认 最新

  • dsapkqaduj6718493 2015-08-27 17:01
    关注

    So if i do understand you there is a many-to-many relationship between discipline and playlist. Then Doctrine can make the join-table for you automatically. You don't need to make it yourself and also you don't need a primary id column. (You never need an id column on a join-table).

    Check this example but change all annotations by inserting the letters ORM\ after the @ so that they will start with @ORM\ .

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?