B
B
BonBon Slick2021-09-16 12:33:11
Doctrine ORM
BonBon Slick, 2021-09-16 12:33:11

How to handle cases when FK is an empty string?

No idea how such records get into the database and where to look for them.
But any ORM will give an error when getting a connection, for example

"Entity of type 'Test\Entity\DoctrineEntity' for IDs relatedEntityFKID() was not found"


1 - option, modify all queries, joins and selections by making them WHERE NOT NULL AND WHERE related_fk_id != ''
2 - add checks in the code itself
$related = $entity->relatedEntity()
if('' !== $related->id()){
 // use $related module, contract 
}

3 - drive in a request and update all the data, but there are some difficulties, networking with all such broken data is default, then what? null? Or other? And this will not indicate the source why such entities ended up in the database.

Your actions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2021-09-16
@BonBonSlick

Put real FK in the DBMS and get an error when trying to write incorrectly, like normal people.
Correct historical data in a manner that makes sense for the domain and business requirements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question