mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-2465: ProxyClass load, and empty ids #3093
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (May 21, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user lele19871:
If you have lazy association (example many-to-one) that have empty id (for empty i mean empty string and not null) you (correctly) get EntityNotFoundException.
But i'm working with a system that sometimes put an empty string instead of null in fk fields.
So i've add this little snipped of code __load method in $_proxyClassTemplate, ProxyFactory:
@doctrinebot commented on GitHub (May 21, 2013):
Comment created by @ocramius:
What does
$this->_identifiercontain in your failing case?@doctrinebot commented on GitHub (May 21, 2013):
Comment created by lele19871:
It contains for example
Because on db you find an empty string and not a null value.
@doctrinebot commented on GitHub (May 21, 2013):
Comment created by @ocramius:
If I get it correctly, you are using empty strings to emulate NULL references, which is invalid in SQL ( I've explained it extensively at http://stackoverflow.com/questions/15502408/doctrine-2-use-default-0-values-instead-of-null-for-relation/15511715#15511715 )
Is this what you are doing? Because for any identifier that is not NULL an attempt to load it should be run, regardless of its content.
@doctrinebot commented on GitHub (May 21, 2013):
Comment created by lele19871:
That's not me :)
It's the system by which i'm sharing the db.
It uses MyIsam engine with no fk or index, so i've found this way to skip load when on db i've empty strings.
Are there other (maybe cleaner) ways?
Thanks,
Gabriele
@doctrinebot commented on GitHub (May 21, 2013):
Comment created by @ocramius:
No, the only correct way to handle this is to set NULL values for the association meta-columns. Marking as invalid
@doctrinebot commented on GitHub (May 21, 2013):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (May 21, 2013):
Comment created by lele19871:
I can't find doc about it: https://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html?highlight=column#annref-column
Can you give an example?
@doctrinebot commented on GitHub (May 21, 2013):
Comment created by @ocramius:
$this->someAssociation = NULL;. That's basically what I mean.@doctrinebot commented on GitHub (May 22, 2013):
Comment created by lele19871:
Mmm, didn't understand.
Anyway, we've tried to fix the old Delphi Monster witch store empty strings instead of nulls... with no results.
So, here is my workaround, maybe this can be useful for other developers who will be in troubles in the future..
In "UnitOfWork" class, public method "createEntity".
[...]
[...]
Regards,
Gabriele
@doctrinebot commented on GitHub (May 22, 2013):
Comment created by @ocramius:
[~lele19871] the ORM does not deal with such architectures (nor with generally invalid usage of RDBMS systems). The only acceptable solution in ORM is with correct NULL values, as it should be, so this patch is invalid.