BeelabTagBundle icon indicating copy to clipboard operation
BeelabTagBundle copied to clipboard

Updating Without TagsText?

Open gothick opened this issue 3 years ago • 4 comments

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? :)

gothick avatar Apr 27 '21 21:04 gothick

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

garak avatar Apr 28 '21 05:04 garak

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.

gothick avatar Apr 28 '21 07:04 gothick

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.

garak avatar Apr 28 '21 07:04 garak

Thank you for clarifying!

gothick avatar Apr 28 '21 07:04 gothick