Extending the Base Classes
While the Service Class and Model Class provide basic functionality for any database table that has metadata configured, it is possible and even encouraged for you to override these base classes with your own that provide specific functionality.
Inherit from Base Classes
In order to extend the base classes, you will need to create a new script file in the folder which is specified in exchange.pikaview.settings.MODELS_ROOT_FOLDER
, refer to Getting Started - Basic Configuration for more information. It is intended that files in this root folder be organized like the example below.
MODELS_ROOT_FOLDER:
- <schema name>:
- <table_1>
- <table_2>
Below is an example of how that would look in the designer, with the MODELS_ROOT_FOLDER
set to "ObjectFolder".
Inherit the Service Class
First, you must inherit from the Service Class, normally located at exchange.pikaview.model_base
like the example below.
class Service(exchange.pikaview.model_base.Service):
tableName = 'pika_test1'
schema = 'PikaviewTesting'
When inheriting the Service class, it is required to specify the tableName
and schema
as a class variable, this points the service to the correct table.
Optionally, it is also possible to override the values of the Read-Only/Read-Write Connections in this script file, like the example below.
class Service(exchange.pikaview.model_base.Service):
tableName = 'pika_test1'
schema = 'PikaviewTesting'
_RO_DB_CONNECTION = 'RO_Connection_Override'
_RW_DB_CONNECTION = 'RW_Connection_Override'
Inherit the Model Class
If only the Service class is inherited, the resulting class will be functional and will use the base implementation of Model as defined in exchange.pikaview.model_base
. However, if further overriding/inheritance functionality is desired, the model class can also be inherited within the new service class like the example below.
class Service(exchange.pikaview.model_base.Service):
tableName = 'pika_test1'
schema = 'PikaviewTesting'
class Model(exchange.pikaview.model_base.Service.Model):
# insert overridden methods here
Common uses of inheriting the base Model class this way would include providing record specific business logic via the Event Hooks.