Closed
Description
This constraint was thought-out to be used directly on a entity. But in several cases, i used it without a doctrine entity, for example when the form has fields for diferents entities.
In this case i want to have the way to specify not only the field also the entity that belongs the field.
I think that the change will be easy, so i will send a PR soon.
I think that the PR will be on 2.8 it is?
Regards!
Activity
webmozart commentedon Jun 10, 2015
Hi @desarrolla2, thank you for suggesting this feature! Can you give an example when this would be useful? I don't quite understand what you propose.
desarrolla2 commentedon Jun 10, 2015
I will tell you my current use case.
I have 2 entities: User that extends FOSUser and Profile that contains firstName, lastName, Address, and others.
Now for a current promotion, i need to create a landing page with some fields from entity User and some fields from entity Profile.
Then i need create a model with this form:
later in controller y will use it well
ogizanagi commentedon Jun 14, 2015
I would have said that this PR will indirectly allow you to do such a thing, but it's actually more complex:
I think it's a very particular use case and it does not belong to the UniqueEntity constraint responsibility, because you're applying this constraint on a non-entity object as an intermediate. IMO you'll need your own custom constraint.
Why do you need this intermediate object in the first place ? Is there anything preventing you to define a form with appropriated fields, relying on both Profile and FOSUser entities ? You don't need an intermediate model for this.
Sorry if I misunderstood your use case.
EDIT: After reading the following comments and having experienced this myself, I fully agree we need something like this.
desarrolla2 commentedon Jun 15, 2015
@ogizanagi sorry if I did not explain properly, but I think using intermediate objects for form validation is the right use.
If you always use your entities to validate forms, there are many cases where you can be restricted, here are some examples.
1- complex forms that need several entities.
2- validations require different forms depending on the part of the application in which you are.
kbond commentedon Jun 23, 2015
I also would like this feature. I do my validation on DTO's rather then on the entities themselves.
qpautrat commentedon Mar 1, 2016
👍
This is useful in CQRS context.
I validate my commands. But I have to create a custom
UniqueEntity
validator like @desarrolla2 did.MatTheCat commentedon Mar 30, 2017
Any news on this? I thought
entityClass
addressed this issue but I was mistaken.HeahDude commentedon Jul 30, 2017
I suggest to close this old issue either as duplicate of #22592 or fixed by #15002.