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

Updating Without TagsText? #24

Open
gothick opened this issue Apr 27, 2021 · 4 comments
Open

Updating Without TagsText? #24

gothick opened this issue Apr 27, 2021 · 4 comments

Comments

@gothick
Copy link

gothick commented Apr 27, 2021

Am I right in thinking that if I have an entity that I've previously tagged, if I simply load the entity, change something unrelated to tags on it, and then persist it, that it will lose all the tags? (Because the TagSubscriber setTags method relies on you having called getTagsText/setTagsText, and if you haven't, it will think you mean to remove all the tags?)

Or am I possibly doing something dumb? :)

@garak
Copy link
Member

garak commented Apr 28, 2021

Each time you update an entity, you should pass back every value, even if unchanged.

@gothick
Copy link
Author

gothick commented Apr 28, 2021

I see -- do you have any hints on the best way of doing this when you're updating an entity without using a form? I have things like commands and message handlers and whenever they touch my entity it loses its tags. At the moment I'm working around this by just calling this->getTagsText() in a postLoad Doctrine callback to populate the tag text with the existing Tags, but it seems a bit of a hack. And I'm thinking that if I add Tag relations rather than using setTagsText those relations won't be saved, yes? Just want to make sure I'm understanding what's going on.

@garak
Copy link
Member

garak commented Apr 28, 2021

Forms are unrelated. Once you get an entity, no matter how, and you need to re-save it (again, no matter how), each property of the entity needs to be non-empty (unless, of course, making a property empty is intentional).
In a command/handler scenario, I would populate $tagsText in the command constructor, as soon as I get the entity.

@gothick
Copy link
Author

gothick commented Apr 28, 2021

Thank you for clarifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants