Howto resolve related data in output (not just IDs) for views?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
simonwidjaja's picture

I'm preparing a presentation/workshop for a User Group (Adobe Flex/Flash Platform): "Bringing a Flex frontend and a drupal backend together".
I'm a flex/php/java pro but new to drupal. But after playing around with it for a weekend I really start loving it. No problems with CCK, Themes, Views and Services (XML-RPC and esp. AMFPHP). But there is one unsolved problem left I coudn't solve on my own.

When calling a complex recordset from Flex or in the Service Browser of drupal I always get the foreign key of the related objects - but not the object data itself. In many cases that makes sense (lazy loading etc.). But for simple data exchange it might be easier to simply get a complex generic object with arrays that holds ALL the data, so my Flex client doesn't need to know about the actual data structure.

I bet it is possible. But I don't know how. I don't get all the options in the View-Editor yet.

(my example: 2 content types (video and artist). A video is in interview with 1 or more artists.)

Any ideas?
Looking forward to your hints ;)
Simon

(system info: all newest stable versions)

AttachmentSize
Bildschirmfoto 2010-08-16 um 01.33.41.png67.65 KB
Bildschirmfoto 2010-08-16 um 01.34.11.png51.65 KB
Bildschirmfoto 2010-08-16 um 01.34.52.png48.6 KB

Comments

if you are using views, then

da_twilight's picture

if you are using views, then you can add a relationship with the content type of your reference node. This is present in the top right corner of the view panel . After adding the relationship, u can select the corresponding fields of the reference node. Just make sure that while adding the fields of the reference table , in the settings u choose the appropriate relationship . That would normally come as the first setting option when u add a field.

thanx that works for me!

simonwidjaja's picture

thanx twilight.

Now my example output looks like this:

[1] => stdClass Object
    (
        [nid] => 10
        [node_title] => Interview with Metallica
        [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_name_value] => Metallica
        [node_node_data_field_related_artists_nid] => 9
        [node_node_data_field_related_artists_type] => artist
        [node_node_data_field_related_artists_vid] => 9
        [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_genre_value] => Thrash Metal
    )

Accessing these values within Flex would cause me to access the property of the generic object like this:

myRemoteObject.node_node_data_field_related_artists_node_data_field_artist_name_field_artist_name_value

It works, but it is ugly as hell ;) Is there any possibility to change that property identifier to something more readable? It is really hard to read, document and debug if you have hundreds of properties like that.

Next problem ;)

simonwidjaja's picture

One more thing. Fixing that would make me happy and a new drupal user ;)

If I have a to-many relation (one video can have more than one related artist) my results are weird:

Array
(
    [0] => stdClass Object
        (
            [nid] => 10
            [node_title] => Interview with Metallica
            [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_name_value] => Metallica
            [node_node_data_field_related_artists_nid] => 9
            [node_node_data_field_related_artists_type] => artist
            [node_node_data_field_related_artists_vid] => 9
            [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_genre_value] => Thrash Metal
            [node_node_data_field_related_artists_title] => Metallica - Biggest Metal Band ever
        )

    [1] => stdClass Object
        (
            [nid] => 12
            [node_title] => Mixed Interview
            [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_name_value] => Slipknot
            [node_node_data_field_related_artists_nid] => 11
            [node_node_data_field_related_artists_type] => artist
            [node_node_data_field_related_artists_vid] => 11
            [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_genre_value] => NuMetal
            [node_node_data_field_related_artists_title] => Chaos Metal Head from Iowa
        )

    [2] => stdClass Object
        (
            [nid] => 12
            [node_title] => Mixed Interview
            [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_name_value] => Metallica
            [node_node_data_field_related_artists_nid] => 9
            [node_node_data_field_related_artists_type] => artist
            [node_node_data_field_related_artists_vid] => 9
            [node_node_data_field_related_artists_node_data_field_artist_name_field_artist_genre_value] => Thrash Metal
            [node_node_data_field_related_artists_title] => Metallica - Biggest Metal Band ever
        )
)

There are TWO videos in the database. The first one hast 1 and the second one 2 attached artists. The result should have to objects with internal array that holds all related artists. But it returns three videos total.

Is that related to the delta settings? I didn't find detailed information on "delta". But playing around with it doesn't solve my issue. Then only one of the two artists is included. That sucks. What I'm I doing wrong?