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
Unable to save relationship data using Channel Model when that is the only update to the entry #2806
Comments
@hypatiaindustries thanks for reporting! Just to make sure, if you update another field with the same request, does the relationship get saved in that case? |
@intoeetive Sorry for the delay getting back to you. Yes, it seems to work with another field as well. I just updated a text field and the relationship field saved. So I can confirm it works with both the title and text fields, but I haven't tested beyond that. |
I just ran into a similar issue on another client's site when trying to update a single grid field. After hours of trying to troubleshoot, I remembered this bug and decided to try updating the entry's url_title at the same time and like magic, the grid field update saved correctly in the database as long as I edited the url_title as well. I wonder if there is some kind of logic somewhere in the Channel Model that checks to see if an entry has changed before it attempts to save, and if that logic is returning that nothing has changed in instances where only a single field is changing in entries with lots of fields? |
When the field is changed, EE is calling This however seems to be not the case with Relationships - and as you discovered, Grids, - as the actual field is not being touched. And this is something that we'll need to fix |
Just wanted to check in on this; I had forgotten about this bug until after I spent a few hours trying to update a single grid field with no luck. I see the pull request in here, excited about that. I just wanted to follow up to see if the grid fields would also be addressed in that PR, or if that is a separate issue/bug? |
The fix - when it's ready to release - will be affecting Grids as well |
…ot-saved-if-only-change Resolved #2806 where relationships field data was not saved if that was the only change for ChannelEntry model
Description of the problem
If I try to add a relationship to an existing entry using the Channel Model, the data is not saved unless I update another field in the entry as well.
$entry = ee('Model')->get('ChannelEntry', $entry_id)->first();
// relationship field to update
$entry->field_id_XX = array('data' => [$entry_id_to_relate]);
$entry->save();
The above code will not save the related entry. I tried all versions of the data array, ie
array('data' => array($entry_id_to_relate))
etc
I stumbled on the issue when I tried to update the title, just to see if the entry wasn't saving for some reason. When I added the title to the update before saving, the entry updated the title as well as the relationship field
How To Reproduce
Steps to reproduce the behavior:
Environment Details:
The text was updated successfully, but these errors were encountered: