Skip to Content
author's profile photo Former Member
Former Member

When to use modelService.refresh method?

Hi, is there any need to call modelService.refresh(myModel) after I save the model with the save method?

Reason I am asking is that I often see code like:

...
modelService.save(someModelObject);
modelService.refresh(someModelObject);
...
and I noticed that the save method "returns" (more like mutates) a "fresh" model object after it is called.
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 15, 2015 at 04:06 PM

    You don't need to call refresh after saving.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 15, 2015 at 04:59 PM

    It depends.

    What could happen is the following:

    You modify some attributes of an item and save it. The persistence layer knows which attributes have been changed and only updates those.

    Somebody else has also modified some (other) attributes in the meanwhile.

    Refreshing the item makes sure you get the most-current state of the item (including the saved changes done by somebody else). If you don't refresh, your local copy of the model does not reflect the other changes, if you do, it does.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Yea that was pretty much clear to me, maybe the question title indicated otherwise, I was mostly curious about the code snippet I pasted that I encounter a lot in our code base. But thanks for the reply.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.