How to access a nested PICK column data from a bi-directional PICK array
Hello everyone,
I'll try to explain what I'm trying to do.
I've got 3 Pods: Productions, Credits and People
- Productions Pod - has got a multi-pick, bi-directional field "credits" that relates to the field "production_fk" in the Credits Pod
- Credits Pod - has got a bi-directional field "production_fk" that relates to the field "credits" in the Productions Pod
- Credits Pod - has got a PICK field "person" that relates to the field "name" in the People Pod
What I'm trying to do is to get all the credits for a production (is working) and display corresponding person's name (can't get working).
Code:
<?php
$found_production = false;
global $pods;
$production_slug = pods_url_variable(-1);
$production = new Pod('productions', $production_slug);
if( !empty($production->data) ) {
$found_production = true;
// credits for the specified production
$credits = $production->get_field('credits');
$credits_count = count($credits);
}
?>
When I var\_dump($credits) it contains all the fields in the Credits Pod, exept PICK fields ("production_fk" and "person"). How can I access the PICK fields data??
Would really appreciate any help! Thanks
3 Answers
This is a three level (Productions->Credits->Person) structure, and pods can go only two levels deep yet. So it should be done as Scott said: get credits.id, make a WHERE clause out of it ('WHERE t.id = a OR b OR c etc'), call a new pod for credits, then apply findRecords() using this clause. After that you can go through related Credits data (just a standard loop using fetchRecord as in examples), including it's pick field.
To get PICK data, start a new Pod() for the related Pod and Item ID and get the info that way.
If you want only some simple data, you can use dot traversal trick for get_field().
$production->get_field('credits.production_fk');
You will get array of traversed pick column (not recommended to use for multiple relations).


