Hi,

I'm using Argument Code in the Views module to try to select some nodes from a certain table.

I've realised the reason why I'm struggling is because the table I'm wanting to select from, I'm effectively needing to do a look up in reverse from what Drupal seems to want me to do.

Drupal uses the arguments to create a WHERE condition, except the SQL statement returns the 'nid' values, whereas in this situation I'm wanting to return the field_tag_artist_nid values. I wonder if I can get Drupal to do this at all? If all else fails I'll try directly hacking my code into the template.

I have a table which is called content_field_tag_artist, which has 4 columns:

vid | delta | nid | field_tag_artist_nid

When I choose Node Reference: Associated Artists (field_tag_artist) as an argument, and use the following argument code:

if (arg(0) == 'node' && is_numeric(arg(1))) {
    $args[0] = arg(1);
}

return $args;

It appears to build a WHERE statement similar to this:

SELECT nid from content_field_tag_artist WHERE field_tag_artist_nid = [arg(1)]

Which makes sense, but in this case I'm wanting to do the look up in reverse, to go from looking at one of the nids and finding the related artists (the field_tag_artist_nid values).

Effectively I would like to use the same table, but create an SQL statement similar to:

SELECT field_tag_artist_nid from content_field_tag_artist WHERE nid = [arg(1)]

Is this possible to do?

Comments

erle’s picture

SELECT field_tag_artist_nid from content_field_tag_artist WHERE nid = [arg(1)]

hmm, If I understand you correctly, what you want is use "NODE: ID" as the argument instead of field_tag_artist_nid to get the above

Then pass the correct nid.

~Erle

l_d’s picture

Hi, how would I then tell Drupal to select the NID from the content_field_tag_artist table in that case? If I choose Node:ID from the argument list instead of field_tag_artist, then my SQL looks like this:

SELECT nid from node WHERE nid = [arg(1)]

Which of course just returns the current node.