This tutorial will demonstrate how to use Views Relationships to access Node Content to a Tripal View. Specifically, a CCK field added the the Chado Feature Content Type will be added to the default Tripal Feature View.
I. Adding a CCK field to Feature Content
The Drupal CCK module allows you, as an administrator, to add non-chado fields to features (or any other kind of Tripal content). The data from these fields will be stored in the drupal database rather then in chado and can be completely specific to your website. In our example, we are adding a source institution field which will be a select field with a small number of hard-coded options.
First, navigate to Administer -> Content Management -> Content Types. This page lists all the content types available on your site including both Tripal and non-Tripal content types. Under operations on the right hand side of the table there should be a manage fields link (If there isn't, you don't have the Drupal CCK module installed correctly). Click on the manage fields link for the Feature content type to add new fields to this content type or to manage existing fields.
Now you will see a listing of all the current fields, as well as, a fieldset near the bottom allowing you to add new fields. To add our new Source Institution CCK we want to fill the following details in the New Field row of the Add fieldset and click Save.
|Field to Fill In||Value||Description|
|Label||Source Institution||This will be the name of the field shown to the user both when the data is entered, edited and viewed|
|Field Name||source_institution||This is the machine readable name of the field|
|Type of Data to Store||Text||The type of data being stored|
|Form Element to edit the Data||Select List||How the user should enter/edit the data|
After saving the new CCK field, you will be brought to an additional form which allows you to customize your field to your exact needs. For example, you can set this field to be required or even allow users to enter multiple values. As indivated by the warning at the top of this form, you have to enter the allowed values for the select list. After entering a couple of options (one options per line), click "Save field settings" at the bottom.
That's it! You have now created a new CCK field which will appear automatically in the create form for features, as well as, the edit and page views. In order to test this out, create a few new features and enter the Source Institution you want (this will provide you with data for the view you will create next).
When you install both Tripal and Views, a number of default views are automatically installed and enabled. One of these default views lists all the features currently in your chado database and can be reached by the Sequence Features primary link. This is the view we are going to use as a starting point for this tutorial.
First, navigate to Administer -> Site building -> Views. Depending on how many views you have created this might be a long list. To filter this list in order to make it easier to find the default feature view we are after, Select "Chado Feature" as the type and "chado" as the tag before clicking Apply. Now click the edit link beside the all_features view.
This will bring you to the views editing page. If you have never used views before there are a number of good tutorials (Here's one) to get you started. If you go to the + beside the Fields header, you will notice that you're new CCK field, which would normally be in the Content group, isn't listed! This is because Views needs to be told that you are interested in all the fields associated with the node.
To tell views that you are interested in all the node fields you need to add a relationship from the feature table to the node table. Since the feature table is linked to the node table through the chado_feature table we actually need to add two relationships.
1. Add the Feature => Chado Relationship
Click on the + sign beside the relationship header to add a new relationship. In the listing of available relationships, check the "Feature: Feature => Chado" relationship and click "Add" then "Update". You have now added the first part of the relationship!
2. Add the Chado => Node Relationship
The relationship from the chado_feature linking table to the node is added in the same way. Click to add a relationship and then in the listing of available relationships, check "Feature: Chado => Node" and click "Add". One addition thing you need to do, is tell views you are chaining relationships by selecting "Feature => Chado" as the relationship before clicking "Update". This tells views that this is the second half of a multi-part relationship. Now that both these relationships are added, you have informed Views that you want to be able to use All fields that you could normally use on a node view.
3. Add your CCK field to the view
Now when you click on the + sign beside the Field heading, you will see a number of additional groups are available including the Content group. To add your Source Institution Field, select the Content Group, check the box beside the Source Institution Field and click Add. This brings you to a form of field specific options, all of which can be left at the default. Thus to finish adding your field, click "Update".
At the bottom of the page, there is a preview of your view. In order to see a listing of fields you have to Change the Organism filter from <None> to <Any> and click Apply. If none of the features shown have data in your CCK field then the Source Institution column will be empty. Enter the name of a feature you created in Section I into the "Name contains" filter and click Apply to see a feature that Does have data for your CCK field.
- In order to add Feature fields to a node view, the two relationships that need to be added are: "Feature: Node => Chado" and "Feature: Chado => Feature". Don't forget that when adding the second one you need to select the first in the relationship box (see above).
- Postgresql only allows for short CCK field names. If your CCK column in your view is empty but the field and value appear on the node page, you might need to shorten the machine name of the field for it to work with views.
- Currently these relationships are only available to link Analysis', Features, Libraries, Organisms and Stocks to their Nodes.