Answers.Body: <p>Assuming your plugin is going to be the only thing referencing this Active Record relationship, your plugin could have its own <code>MyUserRecord</code> that extends Craft's <code>UserRecord</code> and does something like:</p>
  
  <pre><code>public function defineRelations()
  {
      $relations = parent::defineRelations();
  
      $relations['myUser'] = array(static::BELONGS_TO, 'MyUserRecord', 'id', 'required' =&gt; true, 'onDelete' =&gt; static::CASCADE);
  
      return $relations;
  }
  </code></pre>
  
  <p>And you would just utilize <code>MyUserRecord</code> instead of Craft's <code>UserRecord</code> in your plugin.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-16T03:01:42.130Z
Answers.LastActivityDate: 2015-11-16T03:01:42.130Z
Answers.UserDisplayName: Brad Bell
Body: <p>In a custom plugin is it possible to have a element type with a belongs to relationship to a user, as you can only define half of the relationship (without somehow modifying the userRecord). </p>
  
  <p>What would be the best practices to get something like this working?</p>
  
Tags: <plugin-development><relations>
Title: How to handle Belongs To User relationship
ThreadText: # How to handle Belongs To User relationship
  
  (Asked by: username_0 on 2015-11-16)
  
  In a custom plugin is it possible to have a element type with a belongs to relationship to a user, as you can only define half of the relationship (without somehow modifying the userRecord).
  
  What would be the best practices to get something like this working?
  
  **Tags:** plugin-development, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-16. Score: 0 | Accepted answer
  
  Assuming your plugin is going to be the only thing referencing this Active Record relationship, your plugin could have its own `MyUserRecord` that extends Craft's `UserRecord` and does something like:
  
  ```
  public function defineRelations()
  {
      $relations = parent::defineRelations();
  
      $relations['myUser'] = array(static::BELONGS_TO, 'MyUserRecord', 'id', 'required' => true, 'onDelete' => static::CASCADE);
  
      return $relations;
  }
  
  ```
  
  And you would just utilize `MyUserRecord` instead of Craft's `UserRecord` in your plugin.
  
  
  ---
  
  