- DATA MODEL
App::Dochazka::REST::Model::Activity - activity data model
use App::Dochazka::REST::Model::Activity; ...
CREATE TABLE activities ( aid serial PRIMARY KEY, code varchar(32) UNIQUE NOT NULL, long_desc text, remark text )
Activity codes will always be in ALL CAPS thanks to a trigger (entitled
code_to_upper) that runs the PostgreSQL
upper function on the code before every INSERT and UPDATE on this table.
reset (recycles an existing object by setting it to desired state)
TO_JSON (returns 'unblessed' version of an Activity object)
compare (compare two objects)
clone (clone an object)
insert (inserts object into database)
update (updates database to match the object)
delete (deletes record from database if nothing references it)
load_by_aid (loads a single activity into an object)
load_by_code (loads a single activity into an object)
get_all_activities (load all activities)
App::Dochazka::REST::Model::Activity also exports some convenience functions:
aid_exists (boolean function)
code_exists (boolean function)
aid_by_code (given a code, returns AID)
code_by_aid (given an AID, return a code)
activity object workflow, see the unit tests in
This module provides the following exports:
Instance method. Takes the object, as it is, and attempts to insert it into the database. On success, overwrites object attributes with field values actually inserted. Returns a status object.
Instance method. Assuming that the object has been prepared, i.e. the AID corresponds to the activity to be updated and the attributes have been changed as desired, this function runs the actual UPDATE, hopefully bringing the database into line with the object. Overwrites all the object's attributes with the values actually written to the database. Returns status object.
Instance method. Assuming the AID really corresponds to the activity to be deleted, this method will execute the DELETE statement in the database. It won't succeed if the activity has any intervals associated with it. Returns a status object.
Loads activity from database, by the AID provided in the argument list, into a newly-spawned object. The code must be an exact match. Returns a status object: if the object is loaded, the code will be 'DISPATCH_RECORDS_FOUND' and the object will be in the payload; if the AID is not found in the database, the code will be 'DISPATCH_NO_RECORDS_FOUND'. A non-OK status indicates a DBI error.
Analogous method to "load_by_aid".
The following functions are not object methods.
Given a code, attempt to retrieve the corresponding AID. Returns AID or undef on failure.
Given an AID, attempt to retrieve the corresponding code. Returns code or undef on failure.
Optionally takes a PARAMHASH that can contain a 'disabled' key which can be either true or false (defaults to false).
Returns a reference to a hash of hashes, where each hash is one activity object. If 'disabled' is true, all activities including disabled ones will be included, otherwise only the non-disabled activities will be retrieved.