jonathangeiger / kohana-jelly

See the link below for the most up-to-date code
https://github.com/creatoro/jelly
MIT License
146 stars 34 forks source link

Should model->delete() call a delete method on each field to give them a chance to clean up after themselves? #139

Closed vitch closed 14 years ago

vitch commented 14 years ago

Thinking specifically about the File and Image fields - I would like for them to delete the relevant files if the model is deleted. Seems like the easy way to do this would be for model->delete() to loop over the fields and call delete() on each field. This wouldn't do anything in most cases but could be overridden for field types that had some custom delete logic.

The other way I can see to do this is on a per-model basis by overriding delete but that doesn't seem like the correct place to me...

jonathangeiger commented 14 years ago

Probably a good idea. I will implement this.

vitch commented 14 years ago

I'm thinking it will also help with relationships (so that deleting a model can delete all of it's children or any records in a join table related to that model).

I have the basic code here, need to do a little more on some other stuff to be in a position where I can check that the code is working correctly then I'll commit it to my fork. Once I've done that I'll update this issue with a link to the relevant commit incase you want to use it...

jonathangeiger commented 14 years ago

Cool.

vitch commented 14 years ago

Sorry for the delay, forgot to commit before dinner...

Initial work done in http://github.com/vitch/kohana-jelly/commit/82da4ae2255efed9b1174345e0cf5c34ce900492, file and image delete implemented in http://github.com/vitch/kohana-jelly/commit/98d4d09032d859b34160d1fb5cd6b0ba36120d83 and http://github.com/vitch/kohana-jelly/commit/ce0b7d50355c23e48559d9a37abe292f5eafdbb7

jonathangeiger commented 14 years ago

No problem. I'm gonna need a bit of time to look over this. I'll get back to you.

Thanks a lot for your help!