I have defined a content type "solution" which references another node called "task". It works fine to create new nodes by this code:

$edit= array();
$edit['type']= "solution";
$edit['type']= "solution";

// get the node type defaults
$node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'published'));

// default settings
$edit['uid'] = $user->uid;
$edit['name'] = $user->name;
$edit['promote'] = in_array('promote', $node_type_default);
$edit['comment'] = variable_get('comment_'. $edit['type'], 2);
$edit['revision'] = in_array('revision', $node_type_default);
$edit['format'] = FILTER_FORMAT_DEFAULT;
$edit['status'] = in_array('status', $node_type_default); 
$edit['title'] = "Created on the fly!";
  
$edit['field_active'] = array(0 => array('value' => 'True'));
$edit['field_tref'] = array(0 => array('nid' => '7'));

//create and save the node
$new_node = node_submit( $edit);
node_save($new_node);

dev_render gives the following output for field_active and field_tref:

field_active
Array
(
    [0] => Array
        (
            [value] => True
            [view] => True
        )

)


field_tref
Array
(
    [0] => Array
        (
            [nid] => 0
            [view] => 
        )

)

Therefore the structure seems to work, but any values I enter for nid in $edit['field_tref'] = array(0 => array('nid' => '7')); are just discarded. Plus not even an error message comes up.

Any suggestions?

Comments

elwieneko’s picture

Maybe I should add that accessing "field_active" works by the line i use above

$edit['field_active'] = array(0 => array('value' => 'True'));

Just references to other fields don't work.

To put my question the other way around:
Is anybody using this technique and are references working for him/her?

karens’s picture

Status: Active » Closed (won't fix)

Closing old issues. None of us is using the D5 version any more, so hard to provide any support. Sorry.