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

Phalcon 2.0.* - creating object does not set model snapshots. #11007

Closed
temuri416 opened this issue Oct 7, 2015 · 16 comments
Closed

Phalcon 2.0.* - creating object does not set model snapshots. #11007

temuri416 opened this issue Oct 7, 2015 · 16 comments
Milestone

Comments

@temuri416
Copy link
Contributor

Hi,

My model:

class Robots extends Model
{
    public function initialize()
    {
        $this->keepSnapshots(true);
    }
}

Immediately after creating a new instance of model, its snapshot is blank.

That prevents me from checking whether a field has been updated if I decide to update it later during the same request.

Snapshots only get set when loading a model. But they should also be set after a new model is created.

Thanks!

@ashpumpkin
Copy link
Contributor

+1, but I think it's not a bug, but a very annoying feature. Would be very cool if someone will fix it

@temuri416
Copy link
Contributor Author

Snapshot should also be refreshed when Model is saved/updated.

@mzf
Copy link

mzf commented Oct 9, 2015

Old issue. From 1.3.x

@andresgutierrez andresgutierrez changed the title [BUG] Phalcon 2.0.* - creating object does not set model snapshots. Phalcon 2.0.* - creating object does not set model snapshots. Oct 15, 2015
@ruudboon
Copy link
Member

ruudboon commented Mar 1, 2016

Refreshing the object doesn't help.

<?php
$model = new MyModel();
$model->name = "test";
$model->save();
$model->refresh();

I solved this by completely reloading the object :(

<?php
$model = new MyModel();
$model->name = "test";
$model->save();
$model = MyModel::findFirst($model->payment_id);

@ruudboon
Copy link
Member

ruudboon commented Mar 4, 2016

I'm sorry @sergeyklay I don't understand your feedback.

@sergeyklay
Copy link
Contributor

I mean that this is a known issue and I too just had to use this trick

@ruudboon
Copy link
Member

ruudboon commented Mar 4, 2016

Ah sorry! Now I see. Completely clear. Hope to get some time soon to contribute to Phalcon. Love this project.

@temuri416
Copy link
Contributor Author

@andresgutierrez

Any update on this? Do you plan to implement it in 2.1?

Thanks!

@andrew-demb
Copy link
Contributor

Up.
This will be very helpful for development, but if now implement the feature it can break some applications.

@andresgutierrez, can you give us a feedback about this?

@temuri416
Copy link
Contributor Author

@sergeyklay Is this on your radar? :)

@Jurigag
Copy link
Contributor

Jurigag commented Nov 22, 2016

No because 2.0.x is no longer supported. I guess in phalcon 3.0.x we can fix this :D

@temuri416
Copy link
Contributor Author

Sorry, I wasn't expecting this to be fixed in 2.0.x :-) Any hope for this go to on 3.x branch?

@VeryStrongFingers
Copy link

VeryStrongFingers commented Dec 22, 2016

My work around for now is using a base mode class, with the 'afterCreate' method

<?php
class BaseModel {
    //...

    public function afterCreate()
    {
        // I'm using parent because the child classes overload toArray(). For most, $this->toArray() would suffice
        $this->setSnapshotData(parent::toArray());
    }
}

class SomeModel extends BaseModel {

}

$hello = new SomeModel();
if ($hello->create()) {
    var_dump($hello->hasSnapshotData()); //Returns true
}

@Jurigag
Copy link
Contributor

Jurigag commented Mar 3, 2017

I made PR with fix for this, let me know what you think.

@sergeyklay
Copy link
Contributor

Fixed in the 3.1.x branch.

@sergeyklay sergeyklay removed this from the 3.2.x milestone Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants