When create playramework’s model we can use save() or _save() method. Why these both methods are avalible in the framework, what’s the reason? (in this context they do the same – save object to db).
Why I ask this: I have used save() method when doing some validation in it, but the end-user of my class could use _save() if he would want to save without validation. So I ask myself why there are two methods which are both public.
I’ve handled it like this: The problem was with finding the place for
making the validation while saving. In
fact I’ve handled this issue using
@PrePersist anotation for some method
near the save() when I want to be sure
that validation code would be invoced
when persisting. So now I’m ok with
save() and _save() 🙂
Actually, look at the code of save():
So it simply calls _save() and return itself in order to chain calls.
_save is the function containing the real business logic.
save is just a more practical facade for active record design.
Why is _save public and not protected for example ? I don’t really know.
_save() can be called without any problem IMO but it returns void. That’s all 😉