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

Scott Reynolds - June 21, 2009 - 20:05
Title:Node Body Field?» Join Node Revisions table to Activity2

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

pribeh - June 21, 2009 - 20:57

Works perfectly! Thanks.

#3

Scott Reynolds - June 28, 2009 - 23:01

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

sirkitree - July 1, 2009 - 02:12
Status:active» needs work

#5

benroot - July 14, 2009 - 22:04
Status:needs work» needs review

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.

AttachmentSize
activity_node_table_relationship.patch 921 bytes

#6

Scott Reynolds - July 14, 2009 - 22:21

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

benroot - July 15, 2009 - 13:43

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

drewish - July 15, 2009 - 17:30

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

Scott Reynolds - July 15, 2009 - 18:04

I concur, having this is the right way, as opposed to what we have been doing. This should go in.

#10

drewish - July 16, 2009 - 20:59

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.

AttachmentSize
activity_497666.patch 1.36 KB

#11

Scott Reynolds - July 16, 2009 - 21:46
Status:needs review» needs work

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

drewish - July 16, 2009 - 21:53
Status:needs work» needs review

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.

AttachmentSize
activity_497666.patch 920 bytes

#13

pribeh - July 25, 2009 - 16:28

Tested the 497666.patch with the Jul-16 dev version and no luck with getting the node -> body to show up under views.

#14

drewish - July 25, 2009 - 16:44

pribeh, did you clear the views cache before testing it? there's a button to do so under view's tools tab.

#15

drewish - July 25, 2009 - 16:45

pribeh, actually which patch did you try? the one from #12?

#16

pribeh - July 25, 2009 - 17:03

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

pribeh - September 10, 2009 - 07:21

Tested patch with latest Activity dev and still no luck.

#18

Scott Reynolds - September 17, 2009 - 22:12
Status:needs review» fixed

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().

though currently the user is always the node author but I'll address that in the correct issue.

I didn't actually see this at all. It was the proper one.

edit make sure you clear your Views cache

#19

pribeh - September 19, 2009 - 09:50

Works so well!

#20

System Message - October 3, 2009 - 09:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.