-
Notifications
You must be signed in to change notification settings - Fork 3
Working with inheritance
Flextrine supports class table inheritance (CTI) and single table inheritance (STI). You should understand how to map inheritance in Doctrine before reading this chapter.
Inheritance in Flextrine is implemented using interfaces. For example, if you have a parent entity Page
and two child entities WebPage
and DesktopPage
, then this will generate the following AS3 structure:
public interface Page { }
public class WebPage implements Page { }
public class DesktopPage implements Page { }
This means that you can't treat Page
as a real entity from within Flextrine - in effect the parent class is treated as abstract from within Flextrine.
In this situation is would actually be possible to treat Page
as a real entity within Doctrine, so its possible that Flextrine will change the handling of inheritance in a later version. However, this inheritance system has been sufficient for the real-world situations I have so far encountered.
I have found inheritance to be a powerful tool for allowing different entity classes to be queried in a single collection. For example, we could get all Pages with the following query:
em.select(new Query("SELECT p FROM " + QueryUtil.getDQLClass(Page) + " p")).addResponder(new AsyncResponder(onResult, onFault));
private function onResult(e:ResultEvent, token:Object):void {
var pages:Array = e.result;
// pages will contain a selection of WebPages and DesktopPages
}