Drupal 7 node reference field formatter for nid
having trouble creating the patch, here is what I did, added 

'node_reference_nid' =&gt; array(
  'label'       =&gt; t('Nid'),
  'description' =&gt; t('Display the nid of the referenced node.'),
  'field types' =&gt; array('node_reference'),
),


to the node_reference_field_formatter_info() function also added

  case 'node_reference_nid':
  foreach ($items as $delta =&gt; $item) {
    if ($item['access']) {
      $node = $item['node'];
      $result[$delta] = array(
          '#markup' =&gt; check_plain($node-&gt;nid),
       );
      if (!$node-&gt;status) {
        $result[$delta]['#prefix'] = '&lt;span class="node-unpublished"&gt;';
        $result[$delta]['#suffix'] = '&lt;/span&gt;';
      }
    }
  }
  break;


to the node_reference_field_formatter_view() function

that's it, hope it helps