I want to simulate the following simple relationship:
One passenger belongs to a car; One car has many passengers.
The passenger table has an identifier and a Car_id column, the Car table has one identifier column.
My models look like this:
<?php
class Passenger extends AppModel {
var $name = 'Passenger';
var $belongsTo = 'Car';
} ?>
and
<?php
class Car extends AppModel {
var $name = 'Car';
var $hasMany = array (
'Passenger' => array (
'className' => 'Passenger',
'foreignKey' => 'car_id'
)
);
}
?>
and my add Passenger.ctp looks like this:
<?php
echo $this->Form->create('Passenger');
echo $this->Form->input('car_id');
echo $this->Form->end('Save');
?>
BUT, when I go to the page to add a passenger, all I see is an empty drop-down list. Is there another step I must take to populate Dropbox with all the machines?
Chris source
share