<?php

App::uses('Model', 'Model');

/**
 * Application model for Cake.
 *
 * Add your application-wide methods in the class below, your models
 * will inherit them.
 *
 * @package       app.Model
 */

class Distributor extends AppModel {
	public $hasAndBelongsToMany  = array(
				'Depot' => array('className' => 'Depot', 'foreignKey' => 'distributor_id', 'joinTable'=>'distributors_depots'), 
				'Region' => array('className' => 'Region', 'foreignKey' => 'distributor_id')
			);
	public $belongsTo = array(
			'State' => array('className' => 'State', 'foreignKey' => 'state_id', 'fields' => array('id', 'state'), 'type'=>'inner')
		);
	
	public function getList($region_id = 0){
		$conditions = array();
		if ($region_id){
			//$conditions = array('region_id'=>$region_id);
		}
		
		return $this->find('list', array( 'fields'=>array('id', 'title'),'conditions'=>$conditions, 'order'=>array('title'=>'asc')));
	}
	
	
}	