Hi all,

I'm trying to get a relationship to work using 6.x-3.x-dev (2010-Aug-02) but when I save the view I always get a "Broken/missing handler: sometable > ruid" and this relationship is missing until I flush the views cache.

So here is how my code looks like. First my table schema containing a node(nid) - user(ruid) relationship:

  $schema['sometable'] = array(
    'fields' => array(
    'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
    'ruid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
    'rnid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
    ),
    'primary key' => array('nid', 'ruid'),
  );

And here is my hook_views_data and the user relationship:

function mymodule_views_data() {
  $data = array();

  $data['sometable']['table'] = array(
    'group' => t('Reviews'),
    'title' => t('Reviews'),
    'help' => t('User-node relationship.'),
  );
  $data['sometable']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'nid',
    ),
    'users' => array(
      'left_field' => 'uid',
      'field' => 'ruid',
    ),
  );
  
  $data['sometable']['ruid'] = array(
    'title' => t('Uid'),
    'help' => t('User id.'),
    'field' => array(
      'handler' => 'views_handler_field',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter',
    ),
    'relationship' => array(
      'title' => t('Uid'),
      'label' => t('Reviewer Uid'),
      'base' => 'users',
      'base field' => 'uid',
      'skip base' => array('users', 'sometable'),
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['sometable']['nid'] = array(
    'title' => t('Nid'),
    'help' => t('Node id.'),
    'field' => array(
      'handler' => 'views_handler_field',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  return $data;
}

So what am I missing here?
Would be great if someone could help me.

Thanks,
sb

Comments

stephanbauer’s picture

Hi again,

I still can't get it working, I tried with a table base but then it completely stopped working (and I don't want to lose my primary keys).

Could someone give me a hint?
(using Views 6.x-3.x-dev 2010-Aug-18)

Thanks,
sb

dawehner’s picture

You miss

      'handler' => 'views_handler_relationship',

in the relationship defininition :)

stephanbauer’s picture

Hi,

sometimes I'm really blind, but I thought it defaults to 'views_handler_relationship' if not set?
Well, it work now, I guess... :)

Thanks a lot!
sb

dagmar’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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