Accessing Chado Data

Tripal automatically exports the data needed for each template. The $variables variable is an associative array available in all templates. By default Tripal will populate this variable with the record from the appropriate Chado table. For example, for the Chado Feature content type, Tripal will automatically query the Chado feature table and add the record to the variable. The record is then available in the template in the following way:

$feature = $variables['node']->feature;

In the example code, the $feature variable is now an object containing a single record from the feature table. All of the feature table fields are available as elements of the object and can be accessed  in the following way:

$name = $feature->name;
$uniquename = $feature->uniquename;
$feature_id = $feature->feature_id;

When populating the $variables array, Tripal will also recurse through the foreign-key (FK) relationships defined by the table and include objects defined by the FK relationship. For example, the feature table in Chado has a FK relationship with the organism table. Therefore, an organism object will be added to the feature object automatically. The fields for the organism record are then available through the field that participates in the foreign-key relationship. For example, you can access the organism fields in the following way:

$genus       = $feature->organism_id->genus;
$species     = $feature->organism_id->species;
$common_name = $feature->organism_id->common_name;
$organism_id = $feature->organism_id->organism_id;

The object recursion will go as deep as the foreign-key relationships.  Thus, to access the vocabulary that houses the feature type names, the following can be used:

$cv_name = $feature->type_id->cv_id->name
$cv_id   = $feature->type_id->cv_id->cv_id