doqp87012 2018-09-25 04:15
浏览 45
已采纳

Symfony / Doctrine - 从实体构造函数中获取记录?

Using Symfony 4, I'm looking at the documentation for choicetype here and I see this

use App\Entity\Category;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
// ...

$builder->add('category', ChoiceType::class, [
    'choices' => [
        new Category('Cat1'),
        new Category('Cat2'),
        new Category('Cat3'),
        new Category('Cat4'),
    ],

I assume that by calling new Category('Cat1') that it would basically do a lookup in the database of that record based of something like a name field.

How do you do that in the Entity constructor? Unfortunately I don't see any documentation on how that would be done? Or is it just making a new category there (though I fail to see how this would work as it would be missing the database id without a lookup)?

Basically I have the following:

Employee Table
 - employee_id

Employee Roles Table
 - employee_id
 - role_id

Roles Table
 - role_id

So one employee can have many roles. I use a mapping table to do this. What I need is a choicetype that gives me all the roles (all records from Roles table) and then selects the ones that are found in the mapping table (Employee Roles where employee_id = x)

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 车牌识别摄像镜头,httppost,nodejs
      • ¥20 腾讯云托管与本地测试 GET请求获取返回值 完全不同
      • ¥15 C语言有关数组的问题
      • ¥15 edge跟谷歌浏览器的默认搜索引擎无法修改,如何解决?
      • ¥15 access数据库出错
      • ¥100 matlab数学建模习题,求解答
      • ¥15 blender python输出纹理坐标(像素级)与三维坐标的对应关系
      • ¥15 python文件分发
      • ¥15 关于#c语言#的问题:要求:输出格式要界面直观、清晰大方、格式规范
      • ¥15 计算机组成汇编语言电路升级