Tripal
|
Functions | |
chado_generate_var ($table, $values, $base_options=[]) | |
chado_expand_var ($object, $type, $to_expand, $table_options=[]) | |
This API generates objects containing the full details of a record(s) in chado.
chado_expand_var | ( | $object, | |
$type, | |||
$to_expand, | |||
$table_options = [] |
|||
) |
Retrieves fields, or tables that were excluded by default from a variable.
The chado_generate_var() function automatically excludes some fields and tables from the default form of a variable. Fields that are extremely long, such as text fields are automatically excluded to prevent long page loads. Linking tables that have a many-to-one relationship with the record are also excluded. This function allows for custom expansion of the record created by chado_generate_var() by specifying the field and tables that should be added.
Example Usage:
If a field is requested, it's value is added where it normally is expected in the record. If a table is requested then a new key/value element is added to the record. The key is the table's name and the value is an array of records (of the same type created by chado_generate_var()). For example, expanding a 'feature' record to include a 'pub' record via the 'feature_pub' table. The following provides a simple example for how the 'feature_pub' table is added.
where [pub object] is a record of a publication as created by chado_generate_var().
If the requested table has multiple foreign keys, such as the 'featureloc' or 'feature_genotype' tables, then an additional level is added to the array where the foreign key column names are added. An example feature record with an expanded featureloc table is shown below:
$object | This must be an object generated using chado_generate_var() |
$type | Indicates what is being expanded. Must be one of 'field', 'foreign_key', 'table', 'node'. While field and node are self-explanitory, it might help to note that 'table' refers to tables that have a foreign key pointing to the current table (ie: featureprop is a table that can be expanded for features) and 'foreign_key' expands a foreign key in the current table that might have been excluded (ie: feature.type_id for features). |
$to_expand | The name of the field/foreign_key/table/node to be expanded |
$table_options |
|
chado_generate_var | ( | $table, | |
$values, | |||
$base_options = [] |
|||
) |
Generates an object containing the full details of a record(s) in Chado.
The object returned contains key/value pairs where the keys are the fields in the Chado table.
The returned object differs from the array returned by chado_select_record() as all foreign key relationships in the Chado table have been followed and those data are also included. This function automatically excludes some fields and tables. Fields that are extremely long, such as text fields are automatically excluded to prevent long page loads. Linking tables that have a many-to-one relationship with the record are also excluded. Use the chado_expand_var() to manually add in excluded fields and data from linker tables.
Example Usage:
The $values array passed to this function can be of the same format used by the chado_select_record() function.
If a field is a foreign key then its value is an object that contains key/value pairs for that record. The following code provides examples for retrieving values associated with the record, either as columns in the original Chado table or as columns in linked records through foreign keys:
This will return an object if there is only one feature with the name Medtr4g030710 or it will return an array of feature objects if more than one feature has that name.
Note to Module Designers: Fields can be excluded by default from these objects by implementing one of the following hooks:
$table | The name of the base table to generate a variable for |
$values | A select values array that selects the records you want from the base table (this has the same form as chado_select_record) |
$base_options | An array containing options for the base table. For example, an option of 'order_by' may be used to sort results in the base table if more than one are returned. The options must be compatible with the options accepted by the chado_select_record() function. Additionally, These options are available for this function: -return_array: can be provided to force the function to always return an array. Default behavior is to return a single record if only one record exists or to return an array if multiple records exist.
|