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

Unable to save relationship data using Channel Model when that is the only update to the entry #2806

Closed
hypatiaindustries opened this issue Jan 31, 2023 · 6 comments · Fixed by #3355
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.

Comments

@hypatiaindustries
Copy link

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:

  1. Get an existing entry from a channel with a relationship field in it using the Channel Model
  2. Attempt to only update the relationship field
  3. Save the entry
  4. The relationship data shouldn't have saved, if this is reproducable
  5. If you reproduced it, update the same entry's title along with the relationship data to see if they both save correctly

Environment Details:

  • Version: [7.1.5]
  • PHP Version [7.4.33]
  • MySQL Version [8.0.31-0ubuntu0.22.04.1]
  • OS: [Linux: Ubuntu 22.04.1 LTS]
  • Web Server: [Apache 2.4.52]
@intoeetive
Copy link
Contributor

@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?

@hypatiaindustries
Copy link
Author

@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.

@hypatiaindustries
Copy link
Author

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?

@intoeetive
Copy link
Contributor

When the field is changed, EE is calling markAsDirty function which tells that the model record needs to be re-saved - otherwise it's skipped assuming no real change happened.

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

@hypatiaindustries
Copy link
Author

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?

@intoeetive
Copy link
Contributor

The fix - when it's ready to release - will be affecting Grids as well

bryannielsen added a commit that referenced this issue Nov 1, 2023
…ot-saved-if-only-change

Resolved #2806 where relationships field data was not saved if that was the only change for ChannelEntry model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.
Projects
None yet
2 participants