Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorpogeybait4883
    If my findBySQL function looks like this:

    $this->submissions =& $this->Submission->findbySQL('SELECT categories.id AS category_id, categories.name AS category_name, submissions.title,submissions.description AS submissions_description, submissions.soft_delete, submissions.views,submissions.id, submissions.registration_id, submissions.category_id, submissions.contest_id, submissions.created_at
    FROM categories
    INNER JOIN submissions ON submissions.category_id = categories.id
    INNER JOIN finalists ON finalists.submission_id = submissions.id
    WHERE submissions.soft_delete="0" AND submissions.contest_id = ' . $this->Contest->id . '

    Why is it when, in my view, when I do something like...

    foreach($submissions as $submission) {
    echo $submission->category_name;

    it shows nothing. If my understanding is correct, since I am using the findBySQL method on the Submission model and category_name is not part of that model then that field wont be returned in the object. Is that correct? If so, how the heck can I get the value of an aliased field (such as "field_name AS alias") from another table that I am joining (INNER JOIN, LEFT JOIN) on? There must be a way to do this. Before anyone tries to give me this answer, yes I have tried selecting from 'submissions' in the query and inner joining on categories. It doesn't make a difference. It has more to do with the fact that I'm executing findBySQL on the Submission model. Anyone? Bermi?

    -- Pogeybait
    • CommentAuthorarnoschn

    why don't you use the association finder for that?

    $this->submissions =& $this->Submission->findAllBy('soft_delete AND contest_id',0,$this->Contest->id,array('include'=>array('category','finalists'),'returns'=>'array'));

    foreach($submissions as $submission) {
    echo $submission['category']['name'];

    or in sintags:

    {loop submissions}




    P.S: you need a recent trunk version of akelos to use the above finder.