Reputation: 4704
A Representative entity, mapped via joined inheritance to the User entity, in list view shows a count of 3 but displays only one. Representative is also in a ManyToOne relationship to the Nonprofit entity. What needs to happen to show all three Representatives?
The sequence of database queries (seen in the profiler) shows the 6th of 6 queries to return the id of the nonprofit of the representative in list view. I suspect this is strongly related to the fact that only one rep is shown.
Edit: This behavior does not occur in EA2. Only after migrating to EA3.
Edit #2: In EA2 there are 10 db queries vs only 6 in EA3. The difference is that in EA2 there are queries for the properties of nonprofits with ids of 1, 2, & 3; in EA3 there are only queries for the properties of nonprofit with id 3.
Representative entity (snippet):
/**
* @ORM\Table(name="staff")
* @ORM\Entity
*/
class Representative extends User
{
...
/**
* @ORM\ManyToOne(targetEntity="Nonprofit", inversedBy="reps", cascade={"persist", "remove"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="orgId", referencedColumnName="id")
* })
*/
protected $nonprofit;
...
}
User entity (snippet):
/**
* @ORM\Table(name="usertable")
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"rep" = "Representative", "volunteer" = "Volunteer", "admin" = "Admin"})
*/
abstract class User implements UserInterface
{
...
}
Representative CRUD Controller:
class RepresentativeCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Representative::class;
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_EDIT, 'Edit %entity_name%')
->setHelp('index', 'Locking staff deactivates nonprofit and blocks staff log in. Replacing also removes current staff.')
->setSearchFields(['id', 'roles', 'email', 'fname', 'sname', 'confirmationToken', 'replacementStatus']);
}
public function configureActions(Actions $actions): Actions
{
return $actions
->disable('new', 'edit', 'delete');
}
public function configureFields(string $pageName): iterable
{
$roles = ArrayField::new('roles');
$password = TextField::new('password');
$email = TextField::new('email');
$fname = TextField::new('fname');
$sname = TextField::new('sname');
$lastLogin = DateTimeField::new('lastLogin');
$confirmationToken = TextField::new('confirmationToken');
$tokenExpiresAt = DateTimeField::new('tokenExpiresAt');
$locked = BooleanField::new('locked');
$enabled = BooleanField::new('enabled');
$replacementStatus = TextField::new('replacementStatus');
$initiated = DateField::new('initiated');
$completed = DateField::new('completed');
$nonprofit = AssociationField::new('nonprofit');
$id = IntegerField::new('id', 'ID');
$replace = TextareaField::new('replace')->setTemplatePath('Admin/replace_staff.html.twig');
$fullName = TextareaField::new('fullName');
$orgname = TextareaField::new('orgname');
if (Crud::PAGE_INDEX === $pageName) {
return [$replace, $fullName, $email, $orgname];
} elseif (Crud::PAGE_DETAIL === $pageName) {
return [$id, $roles, $password, $email, $fname, $sname, $lastLogin, $confirmationToken, $tokenExpiresAt, $locked, $enabled, $replacementStatus, $initiated, $completed, $nonprofit];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$roles, $password, $email, $fname, $sname, $lastLogin, $confirmationToken, $tokenExpiresAt, $locked, $enabled, $replacementStatus, $initiated, $completed, $nonprofit];
} elseif (Crud::PAGE_EDIT === $pageName) {
return [$roles, $password, $email, $fname, $sname, $lastLogin, $confirmationToken, $tokenExpiresAt, $locked, $enabled, $replacementStatus, $initiated, $completed, $nonprofit];
}
}
}
Upvotes: 1
Views: 1679
Reputation: 317
As mentioned on GitHub i assume that your primary key property is private. Making it protected should solve the problem.
/**
* @ORM\Table(name="usertable")
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"rep" = "Representative", "volunteer" = "Volunteer", "admin" = "Admin"})
*/
abstract class User implements UserInterface
{
protected $id;
}
Upvotes: 2