cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG]:ORM Model::getRelated not reusing already fetched relations

Open rudiservo opened this issue 2 years ago • 1 comments

Describe the bug Model::getRelated() does not reuse already fetched relations that are populated in Model::related and Model::dirtyRelated. getRelated always fetches fresh relations. This makes requests slower and the Database heavier, normally there is no advantage by doing this, it only makes the request longer and the probability of a changed row while executing the request to happen, this is already almost impossible with the expected time of a request to be in the milliseconds.

Expected behavior By default getRelated should reuse the relations in these arrays if not instructed otherwise. Modell has refresh() to update the current model instance, ResultSet does not have this ability yet.

rudiservo avatar Aug 18 '23 11:08 rudiservo

It would be great if the pull request for this issue was merged.
I also noticed this but didn't recognize it as a bug so I just extended the models __get() and getRelated() methods to perform the same check as in the pull request and directly return related[$alias] or dirtyRelated[$alias]. That fit the behavior that we expected and fixed this use case for us.

ZanMaticPratnemer avatar Dec 15 '23 07:12 ZanMaticPratnemer