In general I have been pleased with this module. I have used it to import more than 14000 nodes. I now have another 17000 nodes to import. These new nodes have a nodereference field that refers to the first 14000 nodes.

The problem is that the nodereference field does not always properly import. It is totally random when it works or doesn't work. I have checked and double checked the text and it is a perfect match to the node name.

Is there something I need to do to get the nodereference field to work properly?

Comments

winarcht’s picture

Title: Incorrectly associates Nodereferece Field » The same happens here

I also got this problem.
The node reference fields link to the wrong fields.

jbrauer’s picture

Title: The same happens here » Incorrectly associates Nodereferece Field
websites-development.com’s picture

i've been dealing with importing data into cck. My hack was to add a field in cck that contained a unique id. cck makes a table for each field mapping the node id and that field's value and using a db query you can get the nid based on that known unique value and create the csv file for import with the proper node reference
I am very new to drupal, and if there was a simpler way I've missed please let me know.

vacilando’s picture

Same problem. Perhaps there is an alternative solution for importing nodereference data?

redmood’s picture

I have the same problem too, and i think it will be useful to allow the selection of which filed to use as reference key, i mean:
you've got

PRODUCT with
code,
title,
text

and PRODUCT_PART with
code,
title,
text
and a node_reference_field to PRODUCT

When you try to use node_import module (node_reference importing problem apart) it only uses, as reference key, the $node->nid. But often in real cases, a client export 2 CSV:

1st with the list of PRODUCTs with obvioulsy this columns: code,title,text (and the code normally is never the drupal nid, suppose they're existing products of the client, before the use of drupal...)

2nd with the list PRODUCT_PARTs with this columns: code,title,text,product_code

I know it's possible to set the mappings, but in the case of 2nd file, is not possible to map product_code with the field "code" of PRODUCT, it's only limited to the its nid.

Robrecht Jacques’s picture

Does the nodereference use a "Select List" or "Autocomplete Text Field" widget?

redmood’s picture

select list...

vacilando’s picture

In this version, I also noticed that importing into simple text select list did not work - the values did not even show in the preview and they did not import either. To solve that, I had to change the field type from text select list to simple text, and then later change it back (I could do this because I have single values only -- not sure what happens with multivalues).

I am just saying that select lists, not only in nodereference, may have a common problem.

Perhaps this comment will help debugging this.

jscheel’s picture

This seems to be happening with user references as well.

joachim’s picture

Does this work correctly is the CSV has the node ID rather than the node name?

Bobuido’s picture

I imported a bunch of records yesterday

I had three node reference fields in the target content type - None of these were being mapped (was going to fill them in manually later)

All of these fields pointed to the same node after import

Sounds like the same problem so thought I'd let you know :)

Now that I thought on it some more I've just realised the references were supposed to be referencing a content type I hadn't yet imported the definitions for

Perhaps that was my problem...impatience

a_c_m’s picture

I think the issue could be the search method used by the cck/content.inc


case 'nodereference':
              // If $value is numeric use it, otherwise
              // find a node title that matches and get nid.
              if (intval($value) > 0) {
                $value = intval($value);
              }
              else{
                $referenced_nodes = array();
                $sql = "SELECT nid, title FROM {node} WHERE title SOUNDS LIKE '%s'";
                $result = db_query($sql, $value);
                $record_found = db_fetch_object($result);
                if ($record_found) {
                  $value = $record_found->nid;
                }
              }
              break;

SOUNDS LIKE is a special search method, http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#operator_so... will make best guesses on what you meant. Which could be why it sometimes gets it wrong. Just change the SQL statement to something closer to what you need. e.g. "SELECT nid, title FROM {node} WHERE title = '%s'" for perfect matches.

You may also consider changing the "else{" to "else if(trim($value) != ''){" or you may find matches for rows with no node reference field values (http://drupal.org/node/294315).

Bobuido’s picture

I'll have to admit I don't quite understand what you're talking about

My problem was slightly different to this issue as I didn't want Node Import to fill in the reference and it was guessing for me!

I was able to enter NULL in the node import UI and remove the incorrect entries

Robrecht Jacques’s picture

Status: Active » Closed (duplicate)

Nodereferences had some problems which should be fixed. Select list (or option widgets) had some problems as well which should be fixed as well.

Both fixed will be included in the next release of node_import (5.x-1.8) released later this weekend. Setting this issue as duplicate. Reopen it if yous till have issues after trying 5.x-1.8.

Thanks!