Hi, let’s say we have a “Post” model with the attributes “id” and “value”. What would be the best way to retrieve the row with the highest value? Just like the following query would do it: “SELECT MAX(value) FROM post”
Is there a yii-style way to do this? I guess I would like to be able to retrieve the value like this:
Post::model()->totalCount()
or
Post::model()->totalCount
I tried with statistical query without luck, since it seems to be oriented to retrieve statistics about the child objects of ONE model record, not about all the model records.
I don’t know that you would use a relation for this because the data isn’t really related, Yii needs to know how it’s related. In this case Post is related to Post with id, so that is only ever going to return itself.
Now just say you had a User and Post BELONGS_TO User, then you could (in User):