I have a content type A that references another content type B using a CCK Nodereference select box. Each B node can only be referenced by one A node at a time. This is where Views comes in...

Using the excellent NodeReferrer module and directions i found in this post, I created a view of all the un-referenced B nodes to populate the A node's Nodereference select box. This way a user can only select B nodes that are NOT already in a relationship. It works great, but has one problem. After the user saves the A node and they go back to the A node's Edit form, the B node that they just referenced is not shown in the list (because the view i created excludes referenced nodes). Is there some way that my view could ALSO include the B node currently referenced by the A node the user is editing??

I know i would need to use an argument with the Node ID pulled from the A node being edited; I can get that view to work on its own. What I can't see is how Views could combine that with my current view of un-referenced B nodes.

here's my current view:

$view = new view;
$view->name = 'unreferenced_b_nodes';
$view->description = 'List of B nodes not yet referenced by A nodes.';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'nodereferer_referers' => array(
    'label' => 'Referencing Nodes',
    'required' => 0,
    'referrer_delta' => '-1',
    'referrer_field' => 'field_referenced_b_node',
    'id' => 'nodereferer_referers',
    'table' => 'node',
    'field' => 'nodereferer_referers',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'node',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'relationship' => 'nodereferer_referers',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'a' => 0,
      'b' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '3' => 0,
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_is_member' => 'OG_VIEWS_DO_NOT_VALIDATE_MEMBERSHIP',
    'validate_argument_group_node_type' => array(
      'group' => 0,
    ),
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'b' => 'b',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'nid' => array(
    'operator' => 'not empty',
    'value' => array(
      'value' => '',
      'min' => '',
      'max' => '',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'relationship' => 'nodereferer_referers',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('header_format', '2');
$handler->override_option('header_empty', 0);
$handler->override_option('items_per_page', 25);

Comments

merlinofchaos’s picture

Um. This is a really tough one. Try the views_or module maybe?

nodecode’s picture

ah, i was afraid you might say that :)

Thanks for the suggestion. I think i may just wait for Views 3.x since it looks like it includes OR functionality. I haven't been paying much attention to the new branch but I know it has features for which I have created my own custom modules so i already have good reason to upgrade when the time comes.

dawehner’s picture

Status: Active » Fixed

So this is fixed :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nodecode’s picture

For anyone confused about how this turned out. It was never actually FIXED. I'm waiting for Views3 and making due with Help Text explanations :\

merlinofchaos’s picture

When a feature is added to Views 3 it is fixed. Since it will not be added to Views 2, there's nothing more that will be done. That closes the issue.