(03-13-2017, 01:11 PM)kilishan Wrote: While it's not 100% pretty, I'll add new methods to the model for each situation, something like:
Code:
class Booking extends Model {
public function getTicketsForBooking(int $bookingID)
{
return $this->db->table('tickets')->join('booking_ticket', 'ticket_id = tickets.id')->where('booking_id', $bookingID)->get();
}
}
Or something similar. There's usually some sanity checks in there to make sure that $bookingID is a valid booking, or it throws an exception, etc.
it's not super elegant, but it is straight-forward, easy to follow and understand. Nowadays I'll typically have an actual Repository-type class that holds an instance of the model, and has custom methods for most of the situations I need, which is why it's written like it is, but I've done it straight inside the model class itself many times.
Could you explain more about your repository-type classes?
To use my domain models in my models I've created a basic data mapper (to map arrays to objects) and extended the core model's class to array method.
Kristian Matthews-Kennington
Apple Certified Associate Mac Integration & Management 10.10