CGridView with STAT and such

hello,

so I have the following DB setup:




++++++++++++    +++++++++++++

+ entries  +    +   users   +

++++++++++++    +++++++++++++

+ id       +    + id        +

+ userID   +--->+ firstname +

+ answerID +--- + lastname  +

++++++++++++  | +++++++++++++

              |

++++++++++++  |

+ answers  +  |

++++++++++++  |

+ entryID  +<--

+ answer   +

++++++++++++



My Entry model [i]relations/i looks like this:




return array(

  'user' => array( self::BELONGS_TO, 'User', 'userID' ),

  'hasyes'=> array( self::STAT, 'Answer', 'entryID', 'condition' => 'answer="yes"' )

);



What I’m trying to achieve is to display a link (CGridView under admin) if somebody answered at least 1 yes in the answers table, and make that column searchable and sortable.

I found solution for searching in a user table etc, but not for this one.

thanks,

–iM

If the answers are either yes or no you could change them to 0 and 1 and check for HAVING SUM(answer) > 0