Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthoralexandre
     
    I presume this is really simple, but I can't seem to find a way to do it. I have the following models:

    Auction, which has_one Winner
    Winner, which belongs_to Auction

    If I Auction->find('all',array('include' => 'winner'), how can I test for the presence of a winner when looping through the auctions?

    Thanks in advance!
    •  
      CommentAuthorbermi
     

    Hi Alexandre and welcome to the forum!

    You can perform a simple check with

    if($Account->winner->getModelName() == 'Winner'){
        // winner holds a Winner model
    }else{
        // winner holds an AkAssociatedActiveRecord instance
    }
    

    Regards,

    Bermi

    • CommentAuthoralexandre
     
    Works fine, thank you very much, bermi.

    For the record, coming from a Rails guy who hasn't worked in PHP in 5 years, I would have expected $auction->winner to return false when there is no associated record.