Join Node Revisions table to Activity2
pribeh - June 21, 2009 - 05:48
| Project: | Activity |
| Version: | 6.x-2.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Hey,
I've been testing out activity 2.0 and boy am I excited at the possibilities. One draw back so far - probably just because no one has had the time to get around to it: planning on adding support for node -> body? Fiddling with the default activity/all view but can't find a node ->body field.

#1
Ya spotted this. It is because we don't join the node_revisions table. Really straight forward if you want to paste this into activity.views.inc function activity_views_data_alter
<?php$data['node_revisions']['table']['join']['activity'] = array(
'left_table' => 'activity',
'left_field' => 'nid',
'field' => 'nid',
);
?>
#2
Works perfectly! Thanks.
#3
Do be careful with this change as it can produce duplicates if you have revisions turned on. A better join is needed, it needs to go through node and vid where n.nid = nr.nid AND n.vid = nr.vid.
Supporting multiple revisions will probably not be supported
#4
#5
This patch adds a relationship to the node table. Since node revisions are not involved there is no problem with duplicates. This patch was tested locally and provides access to the node fields and filters when the relationship is utilized in views.
#6
ya but just looking at it tells me that hte node body isn't provided. (note the node body changed from table 'node' to table 'node_revisions' in Views 2.6 and onward)
#7
The node body is available to Activity views using Views 2.6 and the patch in #5. Here is a screenshot of the node body field added to an activity view: http://img.skitch.com/20090715-pdiump84iqgjetaby3g74n85d3.png. The rendered view also displays the node body correctly in my local tests. The ability to utilize the node body as a field is preserved despite the views 2.6 change mentioned in #6.
#8
re #6, i haven't tested benroot's patch but i'm thinking that views would be smart enough to build a join path to revisions once it gets to node.
#9
I concur, having this is the right way, as opposed to what we have been doing. This should go in.
#10
Tested that the node body can be joined correctly.
This goes one step further and adds in a User relation—though currently the user is always the node author but I'll address that in the correct issue.
#11
This needs to get rid of the activity_views_data_alter() $data['node']['join'] stuff as well.
This relationship will replace this.
And as a bonus, it can also get rid of the ugly activity_db_rewrite_sql() because I believe the node_access filter will be exposed as well.
Note: just read the patch didn't apply it to my working copy.
#12
Scott Reynolds, the relationships and joins aren't bidirectional so you'll still need the hook_views_data_alter() to get them in there when node is the base table but your comment made me wonder why use a relationship? We might as well just specify it as a join so that you see User and Node without having to jump through another hoop. If you want the node's user then add a relationship.
I'm not sure how activity_db_rewrite_sql() comes into play. I'll have to give that a look.
#13
Tested the 497666.patch with the Jul-16 dev version and no luck with getting the node -> body to show up under views.
#14
pribeh, did you clear the views cache before testing it? there's a button to do so under view's tools tab.
#15
pribeh, actually which patch did you try? the one from #12?
#16
Tested with the patch in #12 and caches have been reset. The patch Scott Reynolds put forth in number #1 works fine though. Sorry, wish I had more info. The patching process works successfully but just no node->body visible in views.
#17
Tested patch with latest Activity dev and still no luck.
#18
http://drupal.org/cvs?commit=264252
Uses relationships so that we can set the proper base table and such. Brings in all the CCK stuff (got rid of that mess) and allows us to remove hook_db_rewrite_sql().
I didn't actually see this at all. It was the proper one.
edit make sure you clear your Views cache
#19
Works so well!
#20
Automatically closed -- issue fixed for 2 weeks with no activity.