Yii Framework Forum: Getting a single value from a related AR class in a find - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Getting a single value from a related AR class in a find Rate Topic: -----

#1 User is offline   journey4712 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 02-July 09

Posted 15 February 2010 - 12:23 AM

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
0

#2 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 15 February 2010 - 09:01 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users