In this application, I have a Rental model which is central to the application. Rentals are associated with a Client, a Location, and a piece of Equipment. In almost all cases, I want to 'clean' the results, leaving only Rentals that are currently active. However, I don't want to do that in all cases, so what is the best methodology for flagging this?
My current thought is to add a Model variable ( $cleanRentals = true
), and set that flag to false when necessary, and to check the variable in afterFind()
.
Protecting / cleaning data like this on associated models in Cake shows where Cake's model system is lacking. It gets messy.
But I would consider creating a custom finder, something like
$this->Rental->findActive();
Then you could just use that when you want to get only the active rentals.
See more: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#creating-custom-find-types
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.