Below are the schema for Post and Comment
CREATE TABLE Post ( postID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, msg VARCHAR(100), ) ENGINE = InnoDB; CREATE TABLE Comment ( commentID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, postID INT NOT NULL, date DATE NOT NULL, msg VARCHAR(100), CONSTRAINT fk_comment_post FOREIGN KEY (postID) REFERENCES Post (postID) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE = InnoDB;
and the relation in Post Model is specified as:
public function relations() {
return array(
'comments' => array(self::HAS_MANY, 'Comment', 'postID'),
);
}
How to add a relation 'lastestComment' to the Post model to just get the latest Comment?
Thanks.

Help


















