Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorpogeybait4883
    Im about to the end of my rope with pagination. Doing simple pagination is easy if you are pulling data from one database table but what if I'm trying to pull data from 3 database tables? I can do a 2 table pagination with something like this:

    $limit = 15;
    $offset = empty( $this->params['page'] ) ? 0 : $limit * ( intval( $this->params['page'] ) - 1 );
    $sortBy = empty( $this->params['sort'] ) ? 'created_at' : $this->params['sort'];
    $sortDirection = empty( $this->params['direction'] ) ? 'DESC' : strtoupper( $this->params['direction'] );
    $order = $sortBy . ' ' . $sortDirection;

    $this->submission_pages = $this->pagination_helper->getPaginator($this->Submission, array('items_per_page' => $limit ));
    $this->find_options = array(
    'limit' => $limit,
    'offset' => $offset,
    'order' => $order,
    'conditions' => 'contest_id = ' . $this->CurrentContest->id,
    'include' => array('registration')
    $this->submissions =& $this->Submission->find('all',$this->find_options );

    That code works fine and I can use sortable_link:
    %= sortable_link 'title', {}, :link_text => _('Title') %>
    in my view and everything is wonderful. But the problem is, with my app, that the submission object has a relationship with the registration object and the registration object has a relationship with the user object but the submission object does not have a relationship with the user object. So in my submission view if I show fields from submission, registration, and user and try to use the above code by modifying the include to look like:
    'include' => array('registration','user')
    then I get an error because submission and user are not related.

    I need to do a 3 way join such as "SELECT s.*, r.created_at, u.login FROM submissions AS s LEFT OUTER JOIN registrations AS r on s.registration_id = r.id LEFT OUTER JOIN users AS u ON r.user_id = u.id"
    and I was able to use findBySql() to do that as well as create a custom AkPaginator object for pagination but the submission object that I create only includes fields from the submission model even if I specified them in the query in findBySql. So can someone show me how this can be done?

    • CommentAuthorpogeybait4883
    Anyone? Can anyone tell me how this is done? Please? Thanks.