How to join two tables defined in two different bundles?

122 Views Asked by At

I want to join two tables in order to show the details in datagrid.

Table 1: student

  • primary key : id
  • foreign key : class_id

Table 2: class

  • primary key : id

class can have many students. (one to many relationship)

Any suggestions would be appreciated.

I'm using OroCRM

1

There are 1 best solutions below

0
Yaroslav On

You need to add join part to your datagrid.yml configuration. Here is an example in documentation: https://oroinc.com/orocrm/doc/2.6/dev-guide/entities/datagrids#data-source

  1. In case if your bundles know about each other your join may be like this (from student side): join: left: - { join: student.class, alias: class }

Considering that you created entities with the correct mappins. More details can be found here - https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/unitofwork-associations.html https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#one-to-many-bidirectional

  1. If only bundle which holds Class entity should know about students you have to use join table. More details is here - https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#one-to-many-unidirectional-with-join-table