DoctrineBridgeBundle | provides annotations for interlinking entities | Web Framework library
kandi X-RAY | DoctrineBridgeBundle Summary
kandi X-RAY | DoctrineBridgeBundle Summary
This bundle provides a bridge functionality between different doctrine managers. The bridge functionality makes it possible to make interlinked relations between an entity and a document (and vice versa) using annotations. An example for a document:. Using this annotation, it will load a reference object when retrieved, and will be resolved from storage engine when asked for. Also when assigned and saved it will store the UID from the other side, so it can be resolved when retrieved again.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of DoctrineBridgeBundle
DoctrineBridgeBundle Key Features
DoctrineBridgeBundle Examples and Code Snippets
Community Discussions
Trending Discussions on DoctrineBridgeBundle
QUESTION
In my Symfony application, when creating or updating a certain entity, I would like to check whether a duplicate entity already exists, and if it does, display an URL to the existing entity's page together with the error message.
I use Symfony's Validator component with custom constraint classes for my validation, to have reusable validators in different parts of the application - the web controller, console commands, batch processing scripts, etc. I would like $validator->validate($entity)
to validate entity uniqueness as well, using a custom UniqueEntityConstraint
However, I cannot find a way to do this - there doesn't appear to be any way to pass an object from a Constraint Validator
back to the controller.
Is there a way to do what I need using the Validator
component, or am I at a dead end?
Solutions I've explored so far:
DoctrineBridgeBundle
'sUniqueEntity
constraint.
Doesn't return the existing entity or even its ID, just a message that it exists.
- Extend
ConstraintViolation
with a getDuplicateEntity() method.
This would be the optimal solution, but it doesn't work - there appears to be no way to use a custom class without overriding core Symfony code.
- Store the duplicate entity on the Constraint itself and retrieve it using
$violation->getConstraint()->getDuplicateEntity()
.
It would be a dirty hack even if it worked, but it doesn't - ConstraintValidators
reuse the same Constraint instance, so if you were validating multiple entities in a row, getDuplicateEntity()
would only get you the last duplicate from the batch.
ANSWER
Answered 2017-Aug-25 at 12:05Long story short, this is not possible to do with the Validator component. If you want your validation checks to return more than string error messages, you should write a custom service.
I've submitted a feature request to potentially make this possible in the future.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install DoctrineBridgeBundle
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page