We're updating the issue view to help you get more done. 

Working with Set Metadata


I recently posted on the forum about working with set metadata - http://www.collectiveaccess.org/forum/topic.php?id=11947

Seth told me to file a bug here.

The auth details for my Collective Access instance on the website given is -


The PHP script I am running that tries to access metadata is at this URL -

The code in this script is


$c_object = new ca_set_items();
$cArray = $c_object->getApplicableElementCodes();
print "<br />";

$c_search = new SetSearch();
$cr_res = $c_search->search("*");
print "<br />".$cr_res->get("ca_sets.preferred_labels.name");
print "<br />".$cr_res->get("ca_sets.set_description");
print "<br />".$cr_res->get("ca_sets.set_code");
print "<br />".$cr_res->get("ca_set_items.caption");
print "<br />".$cr_res->get("ca_objects.idno");
print "<br />".$cr_res->get("ca_set_items.ca_objects.idno");
print "<br />";


By looking at the results from clicking on the URL and looking at the script, it seems that any data related to Objects in a Set cannot be accessed.



User known
October 31, 2012, 11:12 PM

Thanks. We're looking into this.

User known
November 5, 2012, 12:04 AM

Hi, I finally got a few minutes to actually look at this. There are a couple of problems here. First of all you can't get object data out of a set directly. The objects are related to individual set items, so the process is: (1) load the set (and if you like get set-level metadata) (2) get the items (3) get object data for each item.

Getting the items is a matter of either calling get() on the set to get the item_id's like this:

$va_item_ids = $t_set->get('ca_set_items.item_id', array('returnAsArray' => true));

or using one of the instance methods in ca_sets. Two useful ones:

getItems() returns an array with various information about each item, including some limited data from the underlying object record. Do a print_r() on the array to get an overview of the array's structure.

getItemIDs() returns a simple array of item_ids that you can use to load each item in turn. This is basically the same as the get() formulation above.

Now, the second problem (I said there were two...) is that once you load a set item, say via $t_item = new ca_set_items($vn_item_id) [where $vn_item_id is a valid set item id, of course), you can't use get() to fetch object-level metadata. You can't do this:

print "The idno of the object is ".$t_item->get('ca_objects.idno')."\n";

The issue is a limitation in get() that prevents it from traversing database relationships that are not traditional, explicit primary key-foreign key relationships. Since sets may reference records of any type, not just objects, the relationship between set items and the records they actually reference are stored as generic row_ids + a "table_num" indicator. We will need to extend get to handle these sorts of relationships.

For now, if you want to grab object-level data out of your set items either use getItems() on the ca_sets instance, which includes some object and representation-level data in the array it returns, or load the records manually.

In the end I think we will need to enhance get() so grabbing the underlying object data is transparent to the caller, and perhaps add some more convenience methods at the set level to efficiently grab metadata at all levels. The API for ca_sets is not nearly as nice as it should be. It's origins were pretty haphazard and it shows, I guess.


User known


Asif Ahmed



Affects versions