Describe the bug
Only one row is rendered in a list while I have 2 rows in the database. Pagination doesn't work. Shows 2 results. Filters are working. Works fine for regular entities.
To Reproduce
I have an Entity B that extends abstract Entity A annotated with MappedSuperclass.
/**
* @ORM\Entity(repositoryClass=BRepository::class)
*/
class B extends A
{
....
}
/**
* @ORM\MappedSuperclass(repositoryClass=ARepository::class)
*/
abstract class A
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private ?int $id = null;
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
}
final class BCrudController extends AbstractCrudController
{
public static string $entityFqcn = B::class;
public function configureFields(string $pageName): iterable
{
return [
...
];
}
public static function getEntityFqcn(): string
{
return self::$entityFqcn;
}
}
@SergeC Had the exact same issue a while ago, you need to make the $id property protected, otherwise it's not "visible" in the child classes, at least not in the way EasyAdmin tries to access it.
@lukasluecke It worked. Thanks.
@javiereguiluz Might want to add better handling of this case, I think a helpful error message would be better than this broken behaviour? Or somehow make it work anyway 馃槄
@lukasluecke Is any way to try access getter and if getter doesn't exist fallback to accessing the property and if property private throw an exception. I'm not really happy to have id property protected.
@SergeC Yeah I know, it's just meant as a workaround for now - let's see if there's a nice solution 馃檪 If you have a suggestion maybe you could create a Pull Request?
Reopening since changing property access from private to protected breaks console command.
bin/console doctrine:schema:update --force
Error:
Column name `id` referenced for relation from App\Entity\C towards App\Entity\A does not exist.
The App\Entity\C has ManyToMany relation to entity A
/**
* @ORM\ManyToMany(targetEntity=A::class)
*/
private Collection $a;
I'm afraid I don't know what a MappedSuperclass is. But, if this is related to Doctrine inheritance, I'm afraid that is not supported.
I can't fix this ... but I'm willing to review a fix submitted by the community. The only condition is that it must be an extremely simple and easy-to-maintain fix. If the "fix" requires lots of changes and complex code, we won't add it. I'm sorry if this is disappointing, but I like to be honest.
@javiereguiluz Yeah it's (Doctrine) inheritance - which is working fine for me, with the visibility of the id changed (@SergeC Not sure why it breaks for you, don't think I have ManyToMany-relations on these entities..)
I might create a PR for this next week, but the general fix should be pretty simple. In EntityDto::getPrimaryKeyValue check if property exists on current class, if it does not, try on the parent class instead.
@lukasluecke your solution sounds good. Please ping me I'll test it.
Most helpful comment
@SergeC Had the exact same issue a while ago, you need to make the
$idpropertyprotected, otherwise it's not "visible" in the child classes, at least not in the way EasyAdmin tries to access it.