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

Model::afterFetch() is not fired on Model::refresh() #12220

Closed
Gamblt opened this Issue Sep 14, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@Gamblt

Gamblt commented Sep 14, 2016

Expected and Actual Behavior

When i refresh() a model, afterfetch is not fired.
If refresh() function "re-querying the record from the database" it's necessary to prepare new data using afterfetch().

Provide minimal script to reproduce the issue

I have Users table with afterFetch() function

public function afterFetch()
{
    $empty = empty($this->first_name) && empty($this->last_name);
    $this->full_name = ($empty) ? $this->nick_name : $this->first_name.' '.$this->last_name;
}

So. When i update first_name or last_name save it and refresh() model, the full name is still the same.
It's works good if i use

$user = Users::findFirst($user->id) 

instead of

$user->refresh();
  • Phalcon version: 2.0.11
  • PHP Version: 5.6.25-2
  • Operating System: Ubuntu 14.04
@Jurigag

This comment has been minimized.

Member

Jurigag commented Sep 14, 2016

Well this is not an issue i think. This is just how refresh works. Why fire afterFetch when you have already fetched model ? You just want to refresh it, for sure it shouldn't be in framework. If you want afterFetch fired then just extend refresh method. Refresh is just doing what it says - refreshing model with getting new data from database.

@michanismus

This comment has been minimized.

Contributor

michanismus commented Sep 14, 2016

Hmm, I think it needs to be fired. Otherwise the event should be named "afterFirstFetch"...

@sergeyklay

This comment has been minimized.

Member

sergeyklay commented Sep 14, 2016

@Gamblt The 2.0.x branch is not longer supported. Could you please try 3.0.x version?

@aat2703

This comment has been minimized.

aat2703 commented Sep 29, 2017

Any news on this issue?

@sergeyklay sergeyklay self-assigned this Oct 23, 2017

@sergeyklay sergeyklay added this to the 3.3.x milestone Oct 23, 2017

@sergeyklay sergeyklay modified the milestones: 3.3.x, 3.4.x Mar 24, 2018

@sergeyklay

This comment has been minimized.

Member

sergeyklay commented Mar 25, 2018

Implemented in the 3.4.x branch. Thank you for the report

@sergeyklay sergeyklay closed this Mar 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment