Skip to content
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

Using references in escaped string #1095

Open
vuryss opened this issue Oct 14, 2021 · 4 comments
Open

Using references in escaped string #1095

vuryss opened this issue Oct 14, 2021 · 4 comments

Comments

@vuryss
Copy link

vuryss commented Oct 14, 2021

I have the following case:

App\Entity\News:
  news1:
    id: '<uuid()>'
App\Entity\Preference:
  recommendedNews:
    value: '\["@news1->id"]'

Unfortunately once the array is escaped - meaning I want it as string - the contents of the [ ] are not lexed at all. I tried to find some weird way to get into one of the other regexes, but I couldn't.

My idea is to be able to construct JSON array (in this case) containing references to other entities.

Is that possible in some way or planned to be implemented in the future?

@theofidry
Copy link
Member

Unfortunately I have to plan to work on the lexer bugs in a near future

@alexislefebvre
Copy link
Contributor

Can you use relationships in your database instead?

Or did you try to use an array in the fixtures? Something like that:

App\Entity\Preference:
  recommendedNews:
    value: ["@news1->id"]

Then the setValue() could detect when an array is provided and transform it to a JSON array.

@vuryss
Copy link
Author

vuryss commented Oct 15, 2021

Can you use relationships in your database instead?

Or did you try to use an array in the fixtures? Something like that:

App\Entity\Preference:
  recommendedNews:
    value: ["@news1->id"]

Then the setValue() could detect when an array is provided and transform it to a JSON array.

I don't like to design entities around DB fixtures, it shouldn't accept arrays and convert them to JSON just so that test data gets generated correctly. IMHO this is a bad practice. Unless you actually need that behavior in your normal application.

Moreover this string field might not be necessary in JSON format for all records. In my case, this is a general configuration table - records will be different according to their name.

For now I hardcoded some UUIDs so I don't have to explicitly reference them, but it would be nice if you can use references inside a string.

@alexislefebvre
Copy link
Contributor

I agree that it's bad design, my suggestion was a workaround to avoid being stuck with the error when loading fixtures.

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

3 participants