Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorhaakon
     
    Hi,

    I have an Article model, which has_many comments, which has_one user.

    The article->comments relation works. But when i have the following:

    {loop article.comments}
    Hey {comment.user.username}
    {end}

    Then the user object is never loaded. I have tried with load(), but that is probably just for has_many relations.

    $this->article is fetched this way:
    $this->article = $article->find('first', array('include' => 'user,comments', 'conditions' => array('id' => $this->params['id'])));

    Anyone have any ideas?
    • CommentAuthorhaakon
     
    I have found out that in the latest Akelos revision, you can do the following:

    Controller:
    $this->article = $article->find('first', array('include' => 'user,comments', 'conditions' => array('id' => $this->params['id'])));

    View:

    A lot of article stuff
    // SNIP //
    {loop article.comments}
    <? $comment->user = $comment->user->load(); ?>
    Hey {comment.user.username}
    {end}

    But is this the desired way? I would like if it was possible to refract from having a lot of PHP code in the views..
    • CommentAuthorsuthern
     

    Hey, does your 'conditions' array actually work like that? I've always used this format: 'conditions' => array('id = ?',$this->params['id']) That's nice to know!

    Ruby has pre-fetching (I think it's called that) for more than one level of relationships. I think this feature is planned for Akelos. Bermi?

    For now I just do a simple for loop in my controller (like you have in your view) to load the children.