Getting a single value from a related AR class in a find

Imagine the following situation,

table tvEpisode attributes:

id, tvShow_id, title, airDate,

table tvShow attributes

id, title

i want to do tvShow::model()->with($something)->findAll() such that for each tvShow one tvEpisode is loaded from the database, and i want that one tvEpisode to be the tvEpisode with the highest airDate(stored in unix time() format).

I’m not sure how exactly to go about with this. I have a piece of sql that can be used to generate a table containing the ids of all the tvEpisodes that have the highest airDate, but not sure how to tie it into with(). Is there any way i can specify ‘id IN (subquery)’ or some such with the with() clause?

journey4712

In your rules() definition you define a rule $something.

In this rule’s definition add a sort by airDate and do a limit search of 0,1.