Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthoralexandre
    • CommentTimeNov 9th 2007
     
    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
    • CommentTimeNov 9th 2007
     

    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
    • CommentTimeNov 12th 2007
     
    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.
Add your comments
    Username Password
  • Format comments as