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

#1
I have 3 database tables:
Code:
CREATE TABLE booking
(
   booking_id INT(9) unsigned NOT NULL AUTO_INCREMENT,
   deleted TINYINT(1) DEFAULT '0' NOT NULL,
   created_date_time DATETIME NOT NULL,
   updated_date_time DATETIME,
   CONSTRAINT `PRIMARY` PRIMARY KEY (booking_id)
);

CREATE TABLE booking_ticket
(
   booking_ticket_id INT(9) unsigned NOT NULL AUTO_INCREMENT,
   booking_id INT(9) unsigned NOT NULL,
   ticket_id INT(9) unsigned NOT NULL,
   CONSTRAINT `PRIMARY` PRIMARY KEY (booking_ticket_id, booking_id, ticket_id)
);

CREATE TABLE ticket
(
   ticket_id INT(9) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT,
   ticket_number VARCHAR(255) NOT NULL,
   deleted TINYINT(1) DEFAULT '0' NOT NULL,
   created_date_time DATETIME NOT NULL,
   updated_date_time DATETIME
);

CREATE UNIQUE INDEX ticket_number ON ticket (ticket_number);

But I only want 2 models:
PHP Code:
class Booking extends Model
{
}

class 
Ticket extends Model
{


And 2 domain objects:
PHP Code:
class Booking
{
   public $bookingId;
   public $tickets = [];
}

class 
Ticket
{
   public $ticketId;
   public $ticketNumber;
   public $booking;


How should I handle the `booking_ticket relational table and the domain objects `Booking->tickets` and `Ticket->booking`?

I've got a half-baked solution that I'm really not happy with and would like to see what others solutions are?
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.