Just wondering what’s the best way to create your own entity services (by extending VirtualEntityService) for entities with inheritance.
Say I got a User entity:
component name=“User” persistent=“true” table=“users” output=“false” discriminatorColumn=“userlevel” {
property name=“id” column=“username” fieldtype=“id”;
public User function init() output=“false” {
return this;
}
}
and an PowerUser entity:
component name=“PowerUser” persistent=“true” table=“users” output=“false” extends=“User” discriminatorValue=“1” {
public PowerUser function init() output=“false” {
return this;
}
}
I want to create my own UserService and PowerUserService that extends UserService. But I’m not sure how to do the init part.
component extends=“coldbox.system.modules.cborm.models.VirtualEntityService” singleton{
UserService function init(){
super.init(entityName=“User”, useQueryCaching=true, defaultAsQuery=false);
return this;
}
public string function getUserName() {
// this is a common function to be inherited by all types of users
}
}
component name=“PowerUserService” extends=“UserService” singleton{
PowerUserService function init(){
********************** what do I do here so I don’t break the inheritance defined in the entities themselves?
********************** can I do something like this?
super.super.init(entityName=“PowerUser”, useQueryCaching=true, defaultAsQuery=false);
return this;
}
public string function getSpecialPowers() {
// this is a function for PowerUsers only
}
}