Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – Creating the Post class


We will now create the Post class mapping to the Posts table.

We will need to redefine the table it is mapped to.

We will also need to define its relation to the User table.

package hxBlog;

#ifneko
import neko.db.Object;
import neko.db.Manager;
#end

#ifphp
import php.db.Object;
import php.db.Manager;
#end
class Post extends Object
{
   public var id : Int;
   public var title : String;
   public var body : String;
   public var postedOn : Date;
   public var fk_author : Int;
   
   public var author(dynamic, dynamic) : hxBlog.User;
   
   static function RELATIONS()
   {
      return [{prop: "author", key: "fk_author", manager: User.manager}];
   }
   
   static var TABLE_NAME = "Posts";
   public static var manager = new Manager<Post>(Post);
}

What just happened?

As you can see, we have our imports at the top of the class to ensure that this will work on Neko and PHP.

We also have the fk_author field definition and most importantly, we have...