CCK nodereference is returning empty nid when no node is selected For testing purposes I've installed CCK module on vanila drupal, 
created new node type and attached CCK nodereference to it. 

After creating new node, I've notice in node.tpl.php the following structure:

    [field_my_node_reference] =&gt; Array
    (
        [0] =&gt; Array
            (
                [nid] =&gt; 
                [safe] =&gt; Array
                    (
                    )

                [view] =&gt; 
            )

    )


As you can probably notice, there is a key $node['field_my_node_reference][0]['nid'] that is null. 

In order for me to fully understand CCK - why CCK gives empty keys when nothing is selected?

Any answer is appreciated !
You are looking at a node in CCK's post build_content() phase.  When you add a node reference field to a node, CCK adds the 'nid' portion to the database, and when you build or display the content, it creates the 'safe' and 'view' portions.  If you were doing this manually, you could do something like:

$foo=node_load(27);


and if $foo had a nodereference, $foo would contain

[field_my_node_reference] =&gt; Array
(
    [0] =&gt; Array
        (
           [nid] =&gt;
        )
)


eg, you could print 'my nid is ' . $foo-&gt;field_my_node_reference[0]['nid'];'

and it would print out my nid is [blank] if unset, or my nid is 593 if set.  Now,
when CCK comes in and gets all fancy, it creates the safe and view pieces, and these are set up by those widgets you select in the display fields portion of CCK before getting to node.tpl.  (You can do this yourself by calling $foo=build_content($foo); in a module and looking at $foo again.)  Anyways, CCK works all of that up into the $content variable it aggregates things together into for your node.tpl as well as in the $node variable it has in there if you yourself want to get fancier, eg, print 'this is a link to my node: ' . $node-&gt;field_my_node_reference[0]['view'] would normally print out 'this is a link to my node:' followed by the title of the node linked to it.  All changeable via those display options/widgets.

But as to why it has empty keys, they are just part of the data structure created to ensure everything up and down the workflow works together as well as it does, eg, the safe and view portions are blanks where a link would probably go if the field was set, so that makes sense.  And a NULL is in nid since it hasn't been set.  

But...just plop in some content and you will see everything fill up all nice :)