tags:

views:

673

answers:

3

...or, in other words, how to create a simple join as I would do in SQL?

Suppose I want the following information:

Just as an example:

  • a person's full name
  • a person's hobbies.

His full name is in a (content profile) node type 'name_and_address' and his hobbies are in 'hobbies'.

In SQL, I would link them together by node.uid. I've seen a bit about using relationships, but that goes with user-node-refs. I just want the same user from one content-type and the other.

Now how could I get his name and his hobbies in 1 view?

+2  A: 

There is a how to here does this do the job?

If not...

Views can be extended with custom joins, filters etc. If you are lucky there will be a module for this already. Some modules even provide their own views plugins.

You can write your own views plugins, although the documentation is a little fragmented.

The other thing that should be noted is that views isn't always the answer. Sometimes writing a custom query and display handler will do what you want with much less hassle.

Jeremy French
great article, thx!
Dr. Hfuhruhurr
A: 

Look at the relationships section of the view. This allows you to relate (ie join) different types of content (ie tables). It's not especially intuitive to someone used to SQL, but this video explains much of it. http://www.drupalove.com/drupal-video/demonstration-how-use-views-2s-relationships

AndrewL
yes, but that deals with the sample with company - departments, where the link is being created by the user ref. I dont have that in this situation, because i just want to have the nodes of the same user who created the nodes.
Dr. Hfuhruhurr
A: 

You could use views_embed_view() in your template files to manually specify where they appear (and by extension render one view right below another). You could override this function in a custom module (modulename_embed_view($name, $display_id)) in order to selectively edit what data is allowed out to the page.

Ex):

function modulename_embed_view($name, $display_id) {
  if (strcmp($_GET['q'], 'node/123') === 0) {
    $view = views_get_view($name);
    $view2 = views_get_view('second view');
    $output = $view['some element'] . $view2['element'];
  }
  return $output;
}

I know that this is very much a hack - I just wanted to show how one might use php to manually render and modify views in your template files.

threecheeseopera

related questions