title: How can I make the relation name independent of the related model in CI Datamapper?
body: <p>When designing a relationship in Datamapper one is bound to call the relationship the same name as the related object, which is not too handy when you have something like <code>Application_Model_User</code> as a class name. For those of you who will rush to say that there is a configuration option with "class" key, I know. Been there tried that. It only works for getting a related object, not for updating them.</p>
  
  <p>Here is a code snippet to reproduce the problem:</p>
  
  <pre><code>// User Model
  class UserModel extends Datamapper
  {
      public $table = 'users';
      public $has_many = array(
          'roles' =&gt; array(
              'class' =&gt; 'RoleModel',
              'other_field' =&gt; 'usermodel',
              'join_other_as' =&gt; 'role',
              'join_self_as' =&gt; 'user',
              'join_table' =&gt; 'users_roles' 
          ),
      );
  }
  
  class RoleModel extends DataMapper
  {
      public $table = 'roles';
      public $has_many = array(
          'usermodel' =&gt; array('class'        =&gt; 'UserModel',
                           'other_field'  =&gt; 'roles',
                           'join_other_as'=&gt; 'user',
                           'join_self_as' =&gt; 'role',
                           'join_table'   =&gt; 'users_roles' )
      );
  }
  
  // controller code. Make sure you have a role with INT id = 2, and a user with INT id = 5 in your db
  $user = new UserModel(2);
  $role = new RoleModel(5);
  $user-&gt;save($role);
  </code></pre>
  
  <p>This code gives an "Unable to relate usermodel with rolemodel." error, however it does work properly (meaning a new record is inserted in the join table <code>user_roles</code>) if the relation is renamed from "roles" to "rolemodel".</p>
  
  <p>So, if there are any avid users of CI's Datamapper that could help, please let me know how to properly define relationships.</p>