cakephp memo : basic sql

・普通のSQL。アソシエーションがあるテーブルの値も自動で取得出来る。
fields, conditionsでselect, where.

	public function index(){
	    $users = $this->User->find('all', array(
	        'fields'	 => array('*'),
	        'conditions' => array('group_id =' => '2'),
	    ));
    	$this->set('users', $users);
	}

・inner joinを使う場合。

	public function index(){
	    $users = $this->User->find('all', array(
	        'fields' 		=> array('*'),
	        'conditions' 	=> array('group_id =' => '2'),
            "joins" 		=> array(
                             array("type" => 'INNER',
                                   "table" => 'somethings',
                                   "alias" => 'Something',
                                   "conditions" => 'Something.id = User.id',
                                  ),
                       ),
	    ));
    	$this->set('users', $users);
	}

・ページャを使いたい場合。同様にfields, conditionsでselect, where.
コントローラにはcomponent にPaginatorを設定しておく。

    public $components = array('Paginator');

	public function index(){
		$this->Paginator->settings =  array(
			'fields' 		=> array('User.id', 'User.lastname', 'User.firstname', 'User.email', 'Course.id', 'Course.course_name'),
	        'conditions' 	=> array('group_id NOT' => NULL),
	        'limit' 		=> 10
	    );
	    $data = $this->Paginator->paginate('User');
	    $this->set('users', $data);
	}