Time for action – Adding a post

The function to create a post will have a little twist because it will have to set the author of the post. It will take, among other information, the name of the author. We will then retrieve the author's object by using the manager's search function.

   public static function createPost(authorLogin : String, title : String, body : String) : hxBlog.Post
   {
      var author = hxBlog.User.manager.search({username : authorLogin}, false).first();
      var p = new hxBlog.Post();
      p.author = author;
      p.title = title;
      p.body = body;
      p.postedOn = Date.now();
      p.insert();
      return p;
   }

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.