tags:

views:

16

answers:

0

Is there a way to generate a distinct list in kohana controller ?

function action_load($pid) {
    $v = View::factory('pages/registrationform');
    $programme = ORM::factory('academicprogramme', $pid);
    if ($programme->loaded()) {
        $sid = $programme->mysubject->id;
        $v->subject = ORM::factory('subject')->find($sid);
        $v->subjects = ORM::factory('academicprogramme')->find_all();
        $v->programmes = ORM::factory('academicprogramme')->where('subject','=',$sid)->where('onlineregistration','=',TRUE)->find_all();
        $v->campuses = ORM::factory('campus')->find_all();
    }
    $v->programme = $programme;

    $post = array
            (
            'subject' => $sid,
            'programme' => $pid,
            'fullname' => '',
            'fromaddress' => '',
            'phone' => '',
    );

    $v->post = $post;
    //$v->errors = $post;
    $this->request->response = $v->render();
}

If you look at $v->subjects = ORM::factory(academicprogramme)... you will see that i'm going going through the academicprogramme table in the database to get the list of subjects which is a foreign key in that table. It also has a one to many relationship and thus it would return a list with duplicated subjects.

Is there a way to create the distinct list in the controller so i can just call it in the view?

i've tried using

 $v->subjects = ORM::factory(academicprogramme)->distinct(TRUE)->find_all();

but it still returns a list with duplicated items.