old_contents: var Model = require('base/model')
  var debug = require('debug')('holodex:role:model')
  
  module.exports = Model.extend({
    typeName: 'Role',
    collectionName: 'roles',
  
    props: {
      type: 'link',
      agent: 'link',
      relationship: 'link'
    },
  
    derived: {
      label: {
        deps: ['type', 'agent', 'relationship'],
        fn: function () {
          var agentsByRole = {}
          if (this.relationship) {
            this.relationship.roles.forEach(function (role) {
              agentsByRole[role.type.name] = role.agent.getId()
            })
          } else {
            agentsByRole[this.type.name] = this.agent
          }
          return this.type.generateLabel(agentsByRole)
        }
      },
      linkTypeId: {
        deps: ['type'],
        fn: function () {
          return this.type.getId() + '/link'
        }
      }
    }
  })
  
new_contents: var Model = require('base/model')
  var debug = require('debug')('holodex:role:model')
  
  
  module.exports = Model.extend({
    typeName: 'Role',
    collectionName: 'roles',
  
    props: {
      type: 'link',
      agent: 'link',
      relationship: 'link'
    },
  
    derived: {
      label: {
        deps: ['type', 'agent', 'relationship'],
        fn: function () {
          var agentsByRole = {}
          if (this.relationship) {
            this.relationship.roles.forEach(function (role) {
              agentsByRole[role.type.name] = role.agent.getId()
            })
          } else {
            agentsByRole[this.type.name] = this.agent
          }
          return this.type.generateLabel(agentsByRole)
        }
      },
      linkTypeId: {
        deps: ['type'],
        fn: function () {
          return this.type.getId() + '/link'
        }
      },
      linkTargetId: {
        cache: false,
        deps: ['relationship', 'agent'],
        fn: function () {
          return this.relationship.roles.reduce(function (memo, role) {
            if (role.agent.getId() !== this.agent.getId()) {
              memo = role.agent.getId()
            }
            return memo
          }.bind(this))
        }
      }
    }
  })
  
subject: add linkTargetId to role/model