Welcome Guest, Not a member yet? Register   Sign In
CI 2 & Datamapper - Two foreign keys to same field
#1

I have a database with a table as follows:


Code:
CREATE TABLE `flight_booking` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `flight_id` int(11) NOT NULL,
 `departure_airport_id` int(3) NOT NULL,
 `arrival_airport_id` int(3) NOT NULL,
 PRIMARY KEY (`id`),
 KEY `fk_flight_booking/departure_airport` (`departure_airport_id`),
 KEY `fk_flight_booking/arrival_airport` (`arrival_airport_id`),
 CONSTRAINT `fk_flight_booking/arrival_airport` FOREIGN KEY (`arrival_airport_id`) REFERENCES `airport` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `fk_flight_booking/departure_airport` FOREIGN KEY (`departure_airport_id`) REFERENCES `airport` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION

So, a booking has 2 airports, an arrival and a departure one Thing is, I can't figure out how to declare the relationship in my model. I've tried different things, this is what I have right now:


Code:
   class flight_booking extends DataMapper {
       var $table = 'flight_booking';
       var $has_one = array (
               'flight',
               'departure_airport' => array (
                       'class' => 'airport'
                       ),
               'arrival_airport' => array (
                       'class' => 'airport',
               )
       );
var $validation = array (
           'id' => array (
                   'label' => 'ID',
                   'rules' => array ()
           ),

           'flight_id' => array (
                   'label' => 'Flight ID',
                   'rules' => array (
                           'required'
                   )
           ),

'departure_airport_id' => array (
                   'label' => 'Departure airport id',
                   'rules' => array (
                           'required'
                   )
           ),
  'arrival_airport_id' => array (
                       'label' => 'Arrival aiport ID',
                       'rules' => array (
                               'required'
                       )
               )
   )

This gives me an "Unable to access an error message corresponding to your rule name: required." error when trying to save Any ideas?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB