Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

softDelete not work #5

Open
jrafaelg opened this issue Jul 1, 2015 · 6 comments
Open

softDelete not work #5

jrafaelg opened this issue Jul 1, 2015 · 6 comments

Comments

@jrafaelg
Copy link

jrafaelg commented Jul 1, 2015

Fatal error: Call to a member function beforeSoftDelete() on array in <my_path>\Models\Behaviors\SoftDelete.php on line 90

https://github.com/perchlayer/webird/blob/master/app/phalcon/common/library/Mvc/Model/Behavior/SoftDelete.php#L90

@dschissler
Copy link
Collaborator

Its been a while since I've worked with this and I've yet to put this code to real use but I recall that that feature was designed to work with the SoftDeleteModelTrait. Hopefully you are using PHP 5.4+. Add the trait to the model and then enabled the Behavior with addSoftDeleteBehavior(). The idea is that the Trait is able to call the appropriate hooks since the Behavior skips the delete hooks with the line $model->skipOperation(true);. This is required to prevent the record from actually being deleted. Its tricky as long as Phalcon continues to support PHP 5.3 without proper closure support.

I have not tested all of the combinations of using the trait and behavior together.

If you find the code too strange or unhelpful then perhaps just use the latest Incubator or Phalcon 2.0 code if it is included natively in the newest version.

@dschissler
Copy link
Collaborator

The SoftDeleteModelTrait adds isSoftDeleting() to the model. You can use this in your model delete hooks to tell the difference between a real deletion and a soft delete if your code requires the specifics to be known.

@jrafaelg
Copy link
Author

jrafaelg commented Jul 2, 2015

I found this code in the phalcon forum.

  • Add the trait to the model
  • php 5.6
  • phalcon 2.0.2

I use the trait and, if coment this lines, apparently works fine, but without this feature.

thanks

@dschissler
Copy link
Collaborator

Are you setting it up like this?

@jrafaelg
Copy link
Author

jrafaelg commented Jul 2, 2015

yes

@dschissler
Copy link
Collaborator

Perhaps check array keys of $options. See if beforeSoftDelete and beforeSoftDelete are present as functions.

@dschissler dschissler added this to the 1.0 milestone Oct 31, 2015
@dschissler dschissler removed this from the 1.0 milestone Mar 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants