/** * Create the topic and the first post. * * @param array $values * @param array $expected * @return $this */ public function create_topic(array $values, array $expected) { $post = new Model_Forum_Post(); // We need to set values before getting the validation $post->values($values, array('user_id', 'content')); // Add the post validation and category_exists. $extra_validation = $post->validation(); $extra_validation->rule('category_id', 'Model_Forum_Category::category_exists'); $topic = $this->values($values, $expected)->create($extra_validation); $post->create_post(array('topic_id' => $topic->id), array('topic_id')); // Set the last_post_id to the newly created post. $topic->last_post_id = $post->id; $topic->save(); $topic->category->topics_count++; $topic->category->save(); return $topic; }