-1

I want to delete my relations to via the $hasone. But because I am using nested set modeling, i want to use my own delete 'function'. How can i do this? CakePHP doesn't use my standard delete-function...

Thanks

Bob
  • 873
  • 1
  • 8
  • 21
  • 1
    You need to be more precise, and show some code what you have tried so far. – mark Oct 22 '13 at 19:58
  • It's not about code. I am asking for a way to set my own delete-function when my application deletes relations – Bob Oct 22 '13 at 20:02
  • Are you trying to "break" (remove) your hasone relationship programmatically? Like the "unbindmodel()" method? (http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html) Or are you trying to override the delete method? – AgRizzo Oct 22 '13 at 20:12
  • Yeah, i want to override the delete method. That's because my 'hasone' works with a nested set model. I have a complicated deletefunction – Bob Oct 22 '13 at 20:57

1 Answers1

1

If you still want to use $this->Model->delete() instead of going into your model and defining your own function like myDelete() (easier and probably a better idea...) - have a look at this post on polymorphism:

Is it possible to overwrite a function in PHP

On another note, Cake's functions are built to support cascading and modifying data through (often complex) model relationships, and you'd be better to work with it if you can.

The manual says this:

You can hook custom logic into the delete process using the beforeDelete and afterDelete callbacks present in both Models and Behaviors.

I'd suggest you see what you can do with that before proceeding, or otherwise just define your own custom function in the model called myDelete() and use that.

Community
  • 1
  • 1
scrowler
  • 24,273
  • 9
  • 60
  • 92
  • Thanks. I found the relations between classes so they will delete if they depend on each other – Bob Oct 26 '13 at 22:30