• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Models & Relational Tables

#3
(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
Apple Certified Associate Mac Integration & Management 10.10
epickris.com
Reply


Messages In This Thread
Models & Relational Tables - by EpicKris - 03-13-2017, 02:39 AM
RE: Models & Relational Tables - by kilishan - 03-13-2017, 01:11 PM
RE: Models & Relational Tables - by EpicKris - 03-13-2017, 02:35 PM
RE: Models & Relational Tables - by kilishan - 03-16-2017, 09:00 AM
RE: Models & Relational Tables - by SakhR - 11-06-2018, 11:02 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.