It seems like the foundry factories have a hardtime persisting entities with a composite primary key, when part of that composition is a foreign entity's id.
edit: Added proper issue description and reproduction.
Please provide at least some code or even a reproducer
Am gonna make a reproduction repo later today. 👍
@nikophil The link to the issue reproduction. https://github.com/MauriceH1/zenstruck-foundry-reproduction-1024
The issue crops up when you have 3 entities, in this case I've used: Company Employee Task
Company has a normal ID Employee has a composite ID composed of a uuid and the Company's ID Task has a composite ID composed of a uuid and the Employee's ID
The error you get is: In ORMInvalidArgumentException.php line 119:
Binding an entity with a composite primary key to a query is not supported. You should split the parameter into the explicit fields and bind them separately.
Reproduction steps:
$ docker compose run --rm backend composer install
$ docker compose run --rm backend bin/console doc:mig:mig
$ docker compose run --rm backend bin/console doc:fix:load
does this kind of mapping works in production code? (without Foundry)
I'm wondering if the problem is really related to Foundry? Or if Doctrine does not allow what you're trying to do?
I got exactly the same error when I transform your code into this:
public function load(ObjectManager $manager): void
{
$company = CompanyFactory::createOne([
'businessName' => 'Github',
]);
$employee = EmployeeFactory::createOne([
'name' => 'John Doe',
'company' => $company,
]);
$task = TaskFactory::new([
'employee' => $employee,
'name' => 'Task 1',
])->withoutPersisting()->create();
dump($task);
$this->entityManager->persist($task);
$this->entityManager->flush();
}
notice the ->withoutPersisting() on TaskFactory. The task is actually created by Foundry, but still not persisted. And once persist() is called.... 💥
I do think the problem comes from the mapping + Doctrine, and not Foundry
I'm closing the issue, feel free to reopen it if you still think Foundry is the culprit 😅
@nikophil just got the same issue yes! Am deciding to drop the composite key as it's overengineered anyway.
Apologies for the unnecessary issue!
I've used a similar setup in the past but dropped to plain SQL to persist the object, I guess that's why it worked.