Views 6.x-2.8
CCK 6.x-2.6
Autocreate Node Reference 6.x-2.2
Drupal 6.15

To replicate the problem :
1) Create a content type 'child_type" and save as a template
2) Create another content type "parent_type" with and autocreate node reference field "child_type" and use template
3) Create a view to display the parent node type (Filter - Node Type - parent_type)
4) Add the autocreate node reference field to the view (Content -> Child Type)
5) On the options for the CCK field, select "Full Node"
6) Create a view display as a page and save.
7) View the page

Notice that there are nothing displayed, despite the fact that the the autocreate node reference field is in place and the "child node" has been successfully created.

Notice also that when you view the parent node at /node/[id], the child nodes are displayed correctly as linked titles.

If using the normal node reference field, and displaying the ckk field in the same way (Content -> child node -> Format:Full Node in the "fields" section of the View UI), it works as expected. The node is fully displayed.

In the database, the reason why the normal node is referencing correctly is because the "content_type_[name]" table in the database is populated correctly.

However, in the same table, the autocreate node reference populates a row in the table, but the nid that is associated with the autocreated node is incorrect. I've tried several times and each time I see a value of "5", regardless of what the node id of the node being automatically created actually is.

Comments

socratesone’s picture

#1 under "To replicate the problem :" should read:
1) Create a content type 'child_type" and save. Create an instance of this content type and save as a template.

socratesone’s picture

I've notice another issue while crawling through the database -

In the "content_type_[parent_type]" table, I'm getting the following values:

vid = 107 (correct value for the instance of content type 'parent_type')
nid = 107
field_[child_type]_nid = 1 (incorrect - node id of the instance of the child content type is actually "108"

socratesone’s picture

I have manually modified to values in the content_type_[typename] tables, but the "Full Node" format is still not formatting the node correctly (it's still not displaying it at all).

I know that the data is now correct, as the I have added a custom PHP field (http://drupal.org/project/views_customfield) to get a view to display the node id. I have a view which takes that node id and displays a cck field from it, which is working.

So there are two problems -
1) When an autocreate node reference is created, the information in the "content_type_[typename]" table is not being populated correctly.
2) When that information is MANUALLY entered with the correct data, the "full node" format is still not displaying anything.

I'll keep troubleshooting to figure out what the problem is with the display.

socratesone’s picture

To see what's going on, I've added:

echo '<pre>' . print_r($element, 1) . '</pre>';

... to the function "theme_autocreate_formatter_full_teaser($element)", which generates the full node format.

This is the result (I've replaced my parent content type name with [parent_type]).

The child type is an instance of page.

The field name is "field_[parent_type]_page" as per the autocreate node reference documentation found here: (http://drupal.org/node/371518), as I have several different templates for different autocreate node reference fields all based on the same content type - page.

Note that both the [node_data_field_[parent_type]_page_field_[parent_type]_page_nid] and the [#item][nid] both have a value of "118", despite the fact that they originally had a value of "5" as described above. This is the value that I have manually corrected in the database.


Array
(
    [#theme] => autocreate_formatter_full
    [#field_name] => field_[parent_type]_page
    [#type_name] => [parent_type]
    [#formatter] => full
    [#node] => stdClass Object
        (
            [nid] => 117
            [node_data_field_[parent_type]_page_field_[parent_type]_page_nid] => 118
            [node_type] => [parent_type]
            [node_vid] => 117
            [type] => [parent_type]
            [vid] => 117
            [build_mode] => 0
        )

    [#delta] => 0
    [#item] => Array
        (
            [nid] => 118
            [#delta] => 0
        )

)

It looks like the code that isn't working is this in the function "theme_autocreate_formatter_full_teaser($element)":

$ref_name = $element['#node']->title .' '. $suffix;  
$ref_nid = db_result(db_query("SELECT nid from {node} WHERE title = '%s'", $ref_name));

It is trying to reference the node by the 'title' value passed in $element[#node], which is absent from the actual $element argument passed to the function.

If I add the following code to the top of the function:

$element['#node'] = node_load($element['#node']->nid);

... the function properly renders the full node.

socratesone’s picture

Status: Active » Closed (fixed)

It looks like this problem may only occur when nesting autocreate fields. (I actually had one content type that autocreate another, which autocreated another) Closing.