Posted by Jboo on June 17, 2009 at 12:28pm
| Project: | Node Relativity |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hi,
I'm looking to create a view with the child nodes and some CCK data to display on the parent node. However, there aren't any views argument settings relevant to this module in the version of Node Relativity i'm using. I've noticed other threads where people have created views with relativity arguments.
Am I missing something? I'd really appreciate it if someone could point out how I can do this.
Thanks in advance.
Comments
#1
I was able to get Parent ID into Views arguments by adding code to relativity.views.inc based on other modules:
function relativity_views_data() {
drupal_set_message('View hook called.');
$data['relativity']['table']['group'] = t('Node Relativity');
$data['relativity']['table']['base'] = array(
'field' => 'nid',
'title' => t('Node Relativity'),
'help' => t('Node Relativity for connecting content types to events.'),
);
$data['relativity']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['relativity']['nid'] = array(
'title' => t('Child Node ID'),
'help' => t('The Node ID of the child node.'),
'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'relationship' => array(
'base' => 'node',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Child Node'),
),
);
$data['relativity']['parent_nid'] = array(
'title' => t('Parent Node ID'),
'help' => t('The Node ID of the parent node.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'relationship' => array(
'base' => 'node',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Parent Node'),
),
'argument' => array(
'name' => t('Post: in specified parent'),
'name field' => 'title', // the field to display in the summary.
'validate type' => 'nid',
'handler' => 'views_handler_argument',
'help' => t('filter by parent'),
),
);
return $data;
}
#2
Thanks for this, it worked great ;)
#3
It's true! Works great! I almost gave up using this module. Thanks a lot!!!
#4
I pasted the above code into relativity.views.inc as suggested, but when I try using Parent Node ID as an argument, I get
"user warning: Unknown column 'relativity.title' in 'field list' query: SELECT relativity.parent_nid AS relativity_parent_nid, relativity.title AS relativity_title [...] in mysite.com/modules/views/includes/view.inc on line 765."
Is there something else I need to add?
#5
Thanks, Village Internet, this was exactly what I was looking for. I've attached this change as a standard patch to make testing easier.
#6
*UPDATE* Nevermind...it ws totally unrelated.
Hello. That patch works wonderfully for me, so thanks for putting it together.
I was wondering if anyone has had problems with using Views "grouping field" option to group the results by node type. I created a view that lists out all child nodes of the current node being viewed, and, for some reason, the nodes are not grouping properly; nodes of different types are being grouped together under the wrong section, etc.
I'd really appreciate it if someone could try to group their results by node type to see if they get the problem as well. Thanks.
#7
There is no need to patch the relativity.views.inc file. All you have to do is to:
1. Create a new view
2. Add a "Relationship" -> Groups: "Node Relativity" -> Check "Node Relativity: Parent Node ID"
3. Give a label like "Parent" and check Require this relationship
Now all parent's fields are available through this relationship, including nid which we can use as an argument:
1. Add an "Argument" -> Groups: "Node" -> Check "Node: Nid"
2. Select the Relationship created above. Set Validator=Node and Argument type=Node ID
That's it!
#8
Anyone else had any luck with this?
I started to patch the relativity.views.inc file with no success (tried TortoiseSVN and GnuWin32 since i dont have ssh access on my host) so I just tried following the instructions from oda. No go for me.
does the file HAVE to be patched or am I just doing somethign wrong?
#9
@oda Thanks for writing these steps, but could you point me in the direction of where to go from here? You say "now all parent's fields are available." How? Let's say I want the parent's title, how do I do this?
#10
Figured it out. Add the Node: Title as another field (even if you already have it listed as a field for the primary node title), then set the relationship to be the parent. Now you have the parent title listed as well as the child title.
#11
Tried to follow the instructions in #7 but didn't get it to work. Cannot understand what I am doing wrong.
I have the node reference field on the child node. On the parent I want to show a view in a panels pane showing all children to this parent node.
I do not get any results. My view shows the "Empty text".
Any ideas?
#12
#7 works perfectly, indeed no need to patch.
@johanbackman: You should check if your panel pane is passing "nid" argument to your view successfully. I had many problems before, especially with dev versions of Panels.
#13
as @chawl commented, there is no need to patch. Read #7 by @ado for more information.
Thanks,
Dave
#14
changing status to closed
#15
How do I get the child nodes? I'm so confused. I have a node that doesn't have any parent nodes, but has a lot of child nodes. If I require the parent node ID, my view becomes empty. Should I have a relationship for "Node Relativity: Child Node ID"? Because I don't have that, only Parent ID. What can I do to get this?
#16
Subscribing.
I too need to get all the CHILDREN nodes for the current nid from URL.
I currently get the Parent Node fields as well as the Current Node fields in my block, regardless on wether or not I use the relationship for the fields
What am I missing?
#17
Hello,
I just applied the patch in comment #5 and i can't get it to work :s
First, in the view.inc file, i don't understand the difference between:
- 'handler' => 'views_handler_field_node' for the array $data['relativity']['nid']
- 'handler' => 'views_handler_field' for the array $data['relativity']['parent_nid']
Why do we use once "views_handler_field_node" and once "views_handler_field" ?
My second issue is that when i'm applying the patch, i can select "Child Node Id" but every field i set with this relationship, the prefix doesnt appear. Is that normal? For example, for the field Node : Title:
- if i set the relationship "Parent Node Id", then the label appears in front of the field : (Parent Node) Node : Title
- if i change the relationship to "Child Node Id", then the label disappears : Node : Title
Is that just a matter of display, and the relation still work? Or am I doing something wrong?
Thanks for the snippet anyway !
#18
Found it:
Using this code, the SQL request make a Left JOIN on the relativity table like this:
LEFT JOIN relativity relativity ON node.nid = relativity.nid
What do you actually need is :
LEFT JOIN relativity relativity ON node.nid = relativity.parent_nid
As I'm using both Child and Parent Relationship, i couldnt modify the relativity.views.inc file. (If you're using only the Child Relationship, then you can change directly :
$data['relativity']['table']['join'] = array('node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
by
$data['relativity']['table']['join'] = array('node' => array(
'left_field' => 'nid',
'field' => 'parent_nid',
),
);
If you need both like me, then you can use this hook to modify the query processed:
function MODULENAME_views_pre_execute(&$view) {if ( $view->name == 'VIEWNAME' ) {
$view->build_info['query'] = str_replace("LEFT JOIN {relativity} relativity ON node.nid = relativity.nid","LEFT JOIN {relativity} relativity ON node.nid = relativity.parent_nid",$view->build_info['query']);
$view->build_info['count_query'] = str_replace("LEFT JOIN {relativity} relativity ON node.nid = relativity.nid","LEFT JOIN {relativity} relativity ON node.nid = relativity.parent_nid",$view->build_info['count_query']);
}
}
As usual, not the nicest solution, but did work for me.
Any comments/improvements welcomed !
Matthieu
#19
Support for this is now in the latest dev version of 6.x.1.
Although Oda's method works (and I actually use it myself), this method provides a simple method of listing all the child nodes by passing the parent nid as an arguement. As Oda correctly states, you will only have the parent node data available to you if you use the views relationship.
Thanks to all on this,
Dave
#20
Im using the 6.x-1.x-dev version but Child Node ID is not available as a relationship, only Parent Node ID, am I missing something?
#21
Should I use the 6.x-1.2 version with the patch instead of the dev version??