Patch to add nodereferrer relationship to Views

chipway-drupal - February 16, 2009 - 11:52
Project:NodeReferrer
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:scroogie
Status:closed
Description

Hi,

This module is great but i can't use a nodereferrer field in views relationship.

Can you add this please ?

Thank you very much.

#1

andypost - February 17, 2009 - 08:26
Status:active» duplicate

views integration and d6 version #259837: Nodereferrer Drupal 6 patches + zip + Views integration

#2

detot - March 18, 2009 - 15:17
Category:feature request» bug report
Status:duplicate» active

still not working with relationships with the nodereferrer 6.x-1.x-dev (March 5, 2009 - 14:15 build)

#3

andypost - March 25, 2009 - 23:15
Status:active» postponed (maintainer needs more info)

What is views relationships?

#4

scroogie - March 30, 2009 - 23:34

Relationships allow you to declare JOIN's in Views queries. For example the file field module adds a JOIN to the files table on the fid column, so you can display fields from the files table in the view. For nodereferrer this could be interesting to realize hierarchies.
Here is a link to the views documentation: http://views.doc.logrus.com/classviews__handler__relationship.html
It's not clear to me how CCK handles this, but I think you need to add a 'views data' op in hook_field_settings.
Filefield does the following in there:

<?php
$data
= content_views_field_views_data($field);
 
$db_info = content_database_info($field);
 
$table_alias = content_views_tablename($field);

 
// Add a relationship for related file.
 
$data[$table_alias][$field['field_name'] .'_fid']['relationship'] = array(
   
'base' => 'files',
   
'field' => $db_info['columns']['fid']['column'],
   
'handler' => 'content_handler_relationship',
   
'label' => t($field['widget']['label']),
   
'content_field_name' => $field['field_name'],
  );
  return
$data;
?>

*update*
I found the place where nodereference does this. It is in field_settings as well:

<?php
   
case 'views data':
     
$data = content_views_field_views_data($field);
     
$db_info = content_database_info($field);
     
$table_alias = content_views_tablename($field);

     
// Filter: swap the handler to the 'in' operator.
     
$data[$table_alias][$field['field_name'] .'_nid']['filter']['handler'] = 'content_handler_filter_many_to_one';
     
// Argument: use node.title for summaries.
     
$data["node_$table_alias"]['table']['join']['node'] = array(
       
'table' => 'node',
       
'field' => 'nid',
       
'left_table' => $table_alias,
       
'left_field' => $field['field_name'] .'_nid',
      );
     
$data[$table_alias][$field['field_name'] .'_nid']['argument']['name table'] = "node_$table_alias";
     
$data[$table_alias][$field['field_name'] .'_nid']['argument']['name field'] = 'title';
     
// Relationship: add a relationship for related node.
     
$data[$table_alias][$field['field_name'] .'_nid']['relationship'] = array(
       
'base' => 'node',
       
'field' => $db_info['columns']['nid']['column'],
       
'handler' => 'content_handler_relationship',
       
'label' => t($field['widget']['label']),
       
'content_field_name' => $field['field_name'],
      );
      return
$data;
?>

*update*
I'm stupid. I just realized that there is nothing in the database to JOIN against. No idea how to do that.

#5

scroogie - March 31, 2009 - 08:12
Status:postponed (maintainer needs more info)» active

Of course there is data. It's the same as for nodereference. We just need to use the other database column (nid instead of $field['field_name'].'_nid' as the key. I didn't find out how to do that yet, but I'm still browsing the Views sourcecode.

#6

spoetnik - April 2, 2009 - 08:26

Seems like this would be a very good implementation;
Bi-directional Node Reference

#7

andypost - April 9, 2009 - 11:51

#6 looks promising so every referrer can to now all referrer's fields so can query but anyway it makes query more complicated and slow (a lot of JOINs)

So using views can make your custom implication (only developer knows his references between nodes)

#8

christopher_skauss - May 20, 2009 - 09:08

Hello!
I have a question on that issue, prior to releasing the 6 version -and many thanks for that!- there was an 'unofficial' views relationship handler for which I sponsored its development and was implemented in the file "nodereferrer_view_handler_relationship_referers.inc" in the views folder.

Now that file does not exist anymore, is there a reason why views relationships have been removed? My guess is it stopped working, so I 'm going to attach it here for future reference in case someone wants to tackle with updating it.

/\
I am stuck with that old version where views relationships still work and am trying to contact the initial developer who wrote the relationship code so that he can take another look at it.

AttachmentSize
nodereferrer_view_handler_relationship_referers.zip 785 bytes

#9

andypost - May 20, 2009 - 14:34

@christopher_skauss thanks for your work but can you provide a patch for current -dev lets make it better

#10

scroogie - May 20, 2009 - 14:46

It's a seperate file, not modified existing files, so you can just add it to the cvs.

#11

christopher_skauss - May 20, 2009 - 17:49
Status:active» needs review

@andypost thanks for the prompt reply! It is indeed a separate file, there isn't anything to patch. But the problem is it does not work, at least on my setup. It used to work, with the initial 6 version of node referrer. My guess is there is not much to change, I don't know how much node referrer has changed since then though.

I am trying to find some time to look deeper into it, however I thought I should post it here so that people interested in Views Relationship can take a look too and perhaps suggest any fixes.

#12

scroogie - May 21, 2009 - 10:37

I think it should actually work. Did you add a nodereferrer_views_api() and nodereferrer_views_handlers() function to the module? This is needed in Views 2 final. Perhaps your version was for an earlier API.

#13

christopher_skauss - May 22, 2009 - 07:12

Tried that, still does not work. I re-added the entry for the relationship handler in nodereferrer_views_handlers() but could not get the handler to appear in the Views UI. Haven't given it much thought though, just a quick one to see if it's easy to fix. And please let me clarify, I am not the original developer of the relationship handler, I paid some other guy to do it, and have asked him a week ago to help out with updating it.

#14

scroogie - May 22, 2009 - 09:53

I couldn't get it to run either. I'm a bit confused right now. It worked in a prior version? Do you have the complete version of the module with running relationships? Perhaps I can find the problem then.

#15

christopher_skauss - May 23, 2009 - 16:29

yes,it did work in the original 6 version plus some patches, I am attaching it with this post. You can find the story around these patches here: http://drupal.org/node/259837

btw, the version I am attaching might have functional relationships, but it throws sql errors on node creation, a bug that has been fixed in newer versions of node referrer afaik.

AttachmentSize
nodereferrer.zip 22.61 KB

#16

scroogie - May 24, 2009 - 12:47

Ah, now I get it. Instead of using the 'views data' op in field_settings it uses the nodereferrer_views_data_alter() hook. I think it's essentially the same. Don't know which one is the 'normal' way, although most other modules seem to use the 'views data' op.
Attached is a patch that adds this original implementation, which works. But let me say that I don't know how good this implementation really is.

AttachmentSize
nodereferrer.patch 3.02 KB

#17

christopher_skauss - May 25, 2009 - 10:22

Thanks scroogie ++1, works Great! Patch applies smoothly, Views Relationships work as expected.

If we get more people to test it I think it can be committed.

#18

andypost - May 25, 2009 - 12:07

I recommend to make issue title is more informative so more people pay there attention to it

Right now I have no ability to test patch but glad to commit if it useful

#19

AudioUnderGround - May 25, 2009 - 12:43

Hello.
Im a Drupal nooby and this is the first time I have ever used the patch system.
I used the cygwin program to use this patch, it seemed to go alright (no error messages), but now whenever I go on a page that invloves using views I get an error message.

Fatal error: require_once() [function.require]: Failed opening required './modules/nodereferrer/views/nodereferrer.views.inc' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\drup\modules\views\views.module on line 524

The file is still there however....
Sorry if I am being stupid.

Thnks...

#20

scroogie - May 25, 2009 - 17:55
Title:Can't use nodereferrer field in views relationship» Patch to add nodereferrer relationship to Views
Category:bug report» feature request
Assigned to:Anonymous» scroogie

AudioUnderGround: This seems to be a configuration error, or the patch failed to apply. Do you have any .rej files in that folder? From which folder did you apply the patch?

#21

AudioUnderGround - May 25, 2009 - 21:50

There are no .rej files in that folder.
I put the patch file in the views folder of the nodereferrer module folder.
I then cd to the nodereferrer views folder and applied the patch from there.

#22

scroogie - May 25, 2009 - 22:04

Can you try another module that adds a views include file, e.g. filefield if you get the same error with them?

#23

christopher_skauss - May 26, 2009 - 06:13

Can you run this code somewhere within your site and give us its output?
drupal_get_path('module', 'nodereferrer').'/views';
As far as I can see you put your modules in the root module folder, not sites/all/modules, which is somewhat non-standard, so let's see if that's the culprit.

#24

AudioUnderGround - May 26, 2009 - 19:05

Oh, I didnt know it was non-standard...cheers for letting me know that chris :p
Should putting the modules in there, then running the update work?

#25

christopher_skauss - May 28, 2009 - 06:01

Haven't tried it myself but a search showed that that's the right way, move them and run update.php
Btw you should not move core modules, only the ones you added afterwards. If you want to be on the safe side you may try taking a db backup before doing that.

#26

AudioUnderGround - May 28, 2009 - 18:42

Ive tried moving an patching....no luck...
Ive tried with a filefield patch...and it ends up doing the exact same thing...

#27

azinck - May 28, 2009 - 19:52

I had the same trouble. The problem seems to have to do with file permissions on Windows using Cygwin. I can't really explain it but I've done a little research and this is what I've found:

- If you run "ls -l" in the directory with the patched files you'll find the files that the patch has touched DON'T have a "+" at the end of the permissions listing while the untouched files DO. My understanding is that the "+" indicates that the file has some sort of complex ACL permissions granted it.

- There got to be a better way to fix this (hopefully a way to fix it via Cygwin), but what I've done is to simply copy the files using windows explorer. I copy the files that have been patched to a new name, delete the originals, then rename my copy back to the correct name. This lets Windows itself write the files and it then seems to write them with the "correct" permissions (whatever they are). Re-running "ls -l" on the directory confirms the permissions have been changed.

This is kinda janky, I know, but hopefully it gets you back up and running.

#28

AudioUnderGround - May 28, 2009 - 21:27

Thanks Azinck, works a treat.
As does the patch...wohay!
Thanks to everyone who contributed to the module and patch, and cheers for all the help :D
Just a shame I have a Computing Funamentals to revise for the next few days....just my luck...

#29

scroogie - May 28, 2009 - 21:49

So guys, PLEASE tell in this patch WHAT you tried and IF IT WORKED. That is the sense of a review! Otherwise the developer cannot know if this is ready or not. Thanks.

#30

AudioUnderGround - May 28, 2009 - 22:13

Arr ok sorry :)

Well, after sorting out the patching process (as directed by Azinck) I enabled the addon and proceded to modify one of my content types.

I have a content type 'bands' which has all the usual stuff, name, members etc.
I also have a content type 'Albums' which has album name image, tracks etc.

After enabling this addon, I created 2 new fields for the type Album. One, a usual node reference field pointing to the 'bands' name field. This is called
field_album_band_name
The second was a node refererr. Refering node type was set to 'bands' and referring fields my 'Album' node referrence (field_album_band_name).
Save this.
Went to my Band content type and added a node referrers field. Referring node type is 'Albums' and referring fields is
field_album_band_name.
Save this.
Go to my 'band' view. Set up a 'Node: referrers' relationship pointing to
field_album_band_name
Because this is a 'band' view, it displays the band name and other details. I then have a section for teaser style nodes of other types, for example....band discography.
So i add fields from the content type 'Album' giving them the relationship I just made.
Save this.

Now I just create a band. Put the name, members etc. No albums though because the node referrers field does not show in create forms...which is what i needed.
I procced to create a album, and as well as adding name image etc, I also choose the band name from a dropdown list.
Save this.
When I look at a perticular band, i have the band details and the teaser style discography.
Works perfect :)

Sorry if this is hard to read through, I was writing in a rush.

Thanks again.

#31

andypost - May 28, 2009 - 22:41

Example looks a strange to me because:
Band - title, body, node_referrer (to album type)
Album - title, body, node_reference (to band)

create band, then create its albums each of albums should point to band

than when you visit band a list of albums would be shown automatically
when you visit album you see a reference to it's band

So I still cant understand what this patch for...

#32

scroogie - May 28, 2009 - 23:16

It's to do the things you are describing in views. Let's say you want a list of Bands, but only their names, with the title to all of their albums. Some kind of directory.

Or you want to show only Bands, that have albums.

#33

andypost - May 28, 2009 - 23:27

I talk about that for case described by AudioUnderGround there's no need of view

@scroogie But your patch make some views modifications, please describe - seems like adding relation for field, but it's possible to mek with referring to some view which calculates all you need

#34

christopher_skauss - May 29, 2009 - 05:10

One of my use cases for a socnet I am doing right now:
I have photoalbums and photos. Photos have a node reference field that points to photoalbums. I want to create a view and embed it in the photoalbum nodes, that show what photos point to the current photoalbum. See attached view for my implementation.

AttachmentSize
nodereferrer_views_relationship.jpg 185.12 KB

#35

scroogie - May 29, 2009 - 08:01

andypost: you mean embedding a view to the content type? that doesn't solve it if you have different places where your content is displayed. The Views and Relationship way is just more flexible.

#36

AudioUnderGround - May 29, 2009 - 11:01

I think I do need views for my site. While a normal node view does show everything automatically, I will need to pick and choose items for display, i need the arguments, themability etc.

#37

bohemicus - May 31, 2009 - 07:56

subscribing

#38

christopher_skauss - May 31, 2009 - 08:10

if you guys tested this patch and it works ok, please let the maintainer know so that it can be commited.

#39

lesmana - June 5, 2009 - 19:57

I applied the patch in #16 against the latest dev. Applies cleanly. I've only tested it in a simple circumstance (one content type referencing one other content type) but it worked perfectly for my purposes.

#40

lesmana - June 5, 2009 - 20:15

There's a typo, though: "Referers" should be "Referrers".

Actually, I'd vote to change "Referrers Nodes" to "Referencing Nodes". I think it's a slightly more obvious description of the relationship.

#41

andypost - June 7, 2009 - 02:59

So I see 2 positive comments but we should clean strings from #40

I'm going to review this patch next week + some notice fixes

#42

attheshow - June 9, 2009 - 20:14

The #16 patch works OK, unless you need to base the relationship off of an existing relationship. In the attached screenshot, you can see that I based the "Node: Referrers" relationship on the "Courses" relationship. You can see that the title comes out incorrect at that point. It appears to be pulling in the nid incorrectly in this situation.

AttachmentSize
nodereferrer_relationship_based_on_another.png 123.42 KB

#43

andypost - June 17, 2009 - 09:26

Suppose after commiting this patch I can make a release version of this module/
So going to test it now.
And Im still waiting for comments and patches...

#44

scroogie - June 17, 2009 - 10:45

attheshow: Can you explain your situation better? I don't understand it. What is Course? Is it a node reference field? Does the group refer to the course or the other way around? Are you sure you set the right field in the relationship options? It seems to me that you are using the reference field of the objective.

#45

andypost - June 17, 2009 - 14:42

So let's test this patch against -dev
Please use http://drupal.org/node/106862/cvs-instructions/DRUPAL-6--1

AttachmentSize
nf_relationships.patch 4.98 KB

#46

andypost - June 17, 2009 - 14:48

Example as #34

@christopher_skauss check this screen, please

AttachmentSize
references.png 48.52 KB

#47

andypost - June 17, 2009 - 16:15

Patch commited to HEAD so after a time it appears it -dev

#48

attheshow - June 17, 2009 - 16:29

scroogie,

My "Course Objective" content type has a node reference field ("Course") that lets the user indicate which course the objective goes with. I have another content type, "Course Grouping", that has a similar node reference field in which the grouping is associated with a course. Here's my attempt to indicate which content type references another in my screenshot from comment #42:

Course Grouping -> Course <- Course Objective

#49

scroogie - June 17, 2009 - 22:25

attheshow: And did you really choose the fieldname from the 'Course Grouping' content type for the second node-referrer relationship?

#50

attheshow - June 17, 2009 - 22:33

scroogie: The node-referrer relationship is based off of the first relationship (the course associated with the objective). I'm not sure if this answers your question or not. I don't think it's really clicking, what you're asking me. Sorry.

I will say that in the end, I ended up not using two relationships in this manner. I switched it to where my base content type was the course, and then I set up two Node Referrer relationships (one to course objective and one to course grouping). It would have been nice to chain the relationships together, but I just couldn't get it to work for me.

#51

christopher_skauss - June 18, 2009 - 07:36

Tested latest dev and it works great.
@andypost #46 is exactly what I have in my setup, and it works like a treat. Thanks for the update!

#52

andypost - June 18, 2009 - 11:29

@christopher_skauss Can you help to improve documentation here, just some words about #431318: Much requested documentation

So waiting other reviews to roll out RC version

#53

christopher_skauss - June 20, 2009 - 14:52

@andypost Ready! Glad to help!

#54

AudioUnderGround - July 13, 2009 - 13:21

Hiya...how close is this patch to being integrated into the module? cheers.

#55

attheshow - July 13, 2009 - 16:40

@AudioUnderGround: The patch is already included in the latest dev version of the module.

P.S. It's working well for me.

#56

attheshow - July 13, 2009 - 16:40
Status:needs review» reviewed & tested by the community

Marking as RTBC.

#57

andypost - September 22, 2009 - 10:29
Status:reviewed & tested by the community» fixed

Commited to 6-dev, thanx to all

#58

System Message - October 6, 2009 - 10:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.