Skip to content

Unique Entity Assert not calling __toString() method when displaying custom message #28245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
deivid11 opened this issue Aug 22, 2018 · 6 comments

Comments

@deivid11
Copy link

Symfony version(s) affected: 4.1.0

Description
According to the documentation you can use {{ value }} in message option to display a string representation of the invalid entity using the __toString method of the entity class.
I have implemented the __toString method but I'm getting this kind of message "Object of class CLASS identified by "

Possible Solution
I have checked this code but I can't figure out where is the __toString method called. It can be fixed checking if the entity class is implementing __toString before adding the default message.

@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2018

The way that is described in the documentation was implemented in #19227 and broke with #21288.

@dmaicher @HeahDude Can you take a look here and see if that is intended (and we should update the documentation) or if the __toString() case was not considered enough in #21288?

@dmaicher
Copy link
Contributor

@xabbuh @deivid11 I will check this today after work. Maybe we forgot to handle a case there 😕

@HeahDude
Copy link
Contributor

It seems I've proposed some changes thinking it would be better like this, not being aware of the way it was documented. We could use the __toString() as before at first, and then the change introduced as a fallback.

@HeahDude
Copy link
Contributor

see dmaicher#1

@dmaicher
Copy link
Contributor

dmaicher commented Aug 23, 2018

@deivid11 I added a quick fix here:

#28252

Is this the use-case you are having? So a related entity on the entity you are validating is not unique?

See test:

@deivid11
Copy link
Author

@dmaicher yes, that is the use case and it is the fix I was looking for. Thank you!

nicolas-grekas added a commit that referenced this issue Aug 24, 2018
…ueEntityValidator (dmaicher)

This PR was squashed before being merged into the 3.4 branch (closes #28252).

Discussion
----------

[DoctrineBridge] support __toString as documented for UniqueEntityValidator

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28245
| License       | MIT
| Doc PR        | -

This fixes #28245.

It brings back handling `__toString` as documented for invalid values.

Commits
-------

2ac883a [DoctrineBridge] support __toString as documented for UniqueEntityValidator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants