A powerful feature in Cake is the relational data association provided by the model definition. There are four types of associations:
- hasOne
- hasMany
- belongsTo
- hasAndbelongsToMany

After we define the association between 2 models Cake will automatically fetch the data between the “glued” models. For example if the Car model is related to the Image model and is using a hasOne association type when we will retrieve the data using findAll for example in a controller there will be retrived both Car and Image records: $this->Car->findAll()
To use this types of relations correctly is indicated to use naming conventions like:

- Foreign Keys: singular-model-name_id. For example, a foreign key in the "images" table pointing back to the Car a given Image belongs to would be named "car_id".
- Tables name should be at plural
- Model names should be singular form of the tables names.

Example of association and querying data with hasOne between two models Car model and Image model in this cases:

Location: app/models/car.php

PHP:
  1. class Car extends AppModel
  2.   {
  3.     var $name = 'Car';
  4.     var $hasOne = array(Image' =>               
  5.        array('className' => 'Image',
  6.        'conditions' => '',
  7.        'order' => '',
  8.        'dependent' => true,
  9.        'foreignKey' => 'car_id'
  10.        )
  11. // the hasOne array is what Cake is using to create the association between this 2 models
  12.     );
  13.   }

When we will retrieve data using find() or findAll() calls upon Car model we should see our associated Image model data as well.

PHP:
  1. $car = $this->Car->read(null, '20');
  2. print_r($car);
  3.  //will  output:
  4.    (
  5.    [Car] => Array
  6.         (
  7.          [id] => 20
  8.          [name] => Ferrari
  9.          [model] => Testarosa
  10.          [year] => 1977
  11.          [status] => sold
  12.           )
  13.          [Image] => Array
  14.          (
  15.          [id] => 34
  16.          [title] => sqwertmnx312.jpg
  17.          [width] => 200
  18.          [height] = 150
  19.          )
  20.   )