0
votes

I have the next tables in the database:

  • Lift
  • Vehicle
  • Manufacturer

Lift belongsTo Vehicle

Vehicle belongsTo Manufacturer

Manufacturer hasMany Vehicles

LiftsController.php add method:

public function add() {
    if ($this->request->is('post')) {
        $this->Lift->create();
        $this->request->data['Lift']['user_id'] = $this->Auth->user('id');
        if ($this->Lift->save($this->request->data)) {
            $this->Session->setFlash(__('The lift has been saved'));
            $this->redirect(array('action' => 'my_lifts'));
        } else {
            $this->Session->setFlash(__('The lift could not be saved. Please, try again.'));
        }
    }
    $vehicles = $this->Lift->Vehicle->find('all', array('fields' => array('id', 'model', 'manufacturer_id')));
    $towns = $this->Lift->TownFrom->find('list', array('order' => 'county ASC, name ASC', 'fields' => array('id', 'name', 'county')));
    $this->set(compact('users', 'vehicles', 'towns'));
}

LiftsController.php add view:

    echo $this->Form->input('vehicle_id');

A printscreen:

img

So what I need is to display instead of Manufacturer ID's the manufacturer name. In every model the $displayField is set to the correct value

2

2 Answers

0
votes

Try changing:

echo $this->Form->input('vehicle_id');

To

echo $this->Form->input('Vehicle');
0
votes

Change

$vehicles = $this->Lift->Vehicle->find('all', array('fields' => array('id', 'model', 'manufacturer_id')));

To

$vehicles = $this->Lift->Vehicle->find('list', array('conditions' => array('Vehicle.user_id' => $this->Auth->user('id')), 'recursive' => 0, 'fields' => array('Vehicle.id', 'Vehicle.model', 'Manufacturer.title')));