Answers.Body: <p>You'll want to set the <code>authorId</code> of your entry to be the <em>new user's id</em>.</p>
  
  <p>When you delete that user through the control panel, it'll ask "What do you want to do with this person's content?"... At that point, you can just select "Delete it".</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-04T06:56:39.177Z
Answers.LastActivityDate: 2015-12-04T06:56:39.177Z
Answers.UserDisplayName: Lindsey D
Body: <p>It is 100% possible I am going about this the wrong way, so please feel free to correct me.</p>
  
  <p>I have a registration form that creates a user. I have a plugin that is listening to the <code>onSaveUser</code> event:</p>
  
  <p><strong>MyPlugin.php</strong></p>
  
  <pre><code>craft()-&gt;on('users.onSaveUser', function (Event $event) {
      if ($event-&gt;params['isNewUser']) {
          $entry = new EntryModel();
          $entry-&gt;sectionId = 16;
          $entry-&gt;typeId = 1;
          $entry-&gt;enabled = false;
          $entry-&gt;getContent()-&gt;title = craft()-&gt;request-&gt;getPost('firstName') . ' ' . craft()-&gt;request-&gt;getPost('lastName');
  
          ...
  
          if (craft()-&gt;entries-&gt;saveEntry($entry)) {
              // success
          } else {
              // trouble!
          }
      }  
  });
  </code></pre>
  
  <p>Everything works great. The entries I am creating are basically an extension of the user's account (height, weight etc). </p>
  
  <p>I know there are events for deleting a user, but what is the best way to relate the newly created entry so it gets deleted along with the user?</p>
  
  <p>I thought about having an entries field on the actual user account that <em>somehow</em> I populate with the newly created entry?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Or, should I have a <code>user</code> field on the newly created entry? In that case, I'm not sure how I populate the newly created entry with the newly created userID.</p>
  
  <p>For example:</p>
  
  <pre><code>...
  $user = $event-&gt;params['user'];
  $entry = new EntryModel();
  $entry-&gt;sectionId = 16;
  $entry-&gt;typeId = 1;
  $entry-&gt;enabled = false;
  $entry-&gt;getContent()-&gt;title = craft()-&gt;request-&gt;getPost('firstName') . ' ' . craft()-&gt;request-&gt;getPost('lastName');
  
  // account is the handle of my users field
  $entry-&gt;getContent()-&gt;account = $user-&gt;id;  // im not setting this correctly
  
  if (craft()-&gt;entries-&gt;saveEntry($entry)) {
      // success
  } else {
      // trouble!
  }
  
  ...
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-12-03T05:41:44.717Z
Comments.Text: Posting as a comment, since this is off the top of my head... I think you want to set `authorId` of your entry to be the new user's id. Then, when you delete a user (through the control panel), it'll ask "What do you want to do with this person's content?"... at that point, you can just select "Delete it". If this actually helps you solve the problem, I'll post it as an official answer. :)
Comments.UserDisplayName: Lindsey D
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-12-04T01:54:55.093Z
Comments.Text: BRILLIANT! I forgot all about that dialog - works perfectly! Update your comment to the answer and I'll mark it. Thanks Lindsey
Comments.UserDisplayName: Damon
Tags: <plugin-development><users>
Title: How can I delete all entries that belong to a user?
ThreadText: # How can I delete all entries that belong to a user?
  
  (Asked by: username_0 on 2015-12-03)
  
  It is 100% possible I am going about this the wrong way, so please feel free to correct me.
  
  I have a registration form that creates a user. I have a plugin that is listening to the `onSaveUser` event:
  
  **MyPlugin.php**
  
  ```
  craft()->on('users.onSaveUser', function (Event $event) {
      if ($event->params['isNewUser']) {
          $entry = new EntryModel();
          $entry->sectionId = 16;
          $entry->typeId = 1;
          $entry->enabled = false;
          $entry->getContent()->title = craft()->request->getPost('firstName') . ' ' . craft()->request->getPost('lastName');
  
          ...
  
          if (craft()->entries->saveEntry($entry)) {
              // success
          } else {
              // trouble!
          }
      }  
  });
  
  ```
  
  Everything works great. The entries I am creating are basically an extension of the user's account (height, weight etc).
  
  I know there are events for deleting a user, but what is the best way to relate the newly created entry so it gets deleted along with the user?
  
  I thought about having an entries field on the actual user account that *somehow* I populate with the newly created entry?
  
  **EDIT**
  
  Or, should I have a `user` field on the newly created entry? In that case, I'm not sure how I populate the newly created entry with the newly created userID.
  
  For example:
  
  ```
  ...
  $user = $event->params['user'];
  $entry = new EntryModel();
  $entry->sectionId = 16;
  $entry->typeId = 1;
  $entry->enabled = false;
  $entry->getContent()->title = craft()->request->getPost('firstName') . ' ' . craft()->request->getPost('lastName');
  
  // account is the handle of my users field
  $entry->getContent()->account = $user->id;  // im not setting this correctly
  
  if (craft()->entries->saveEntry($entry)) {
      // success
  } else {
      // trouble!
  }
  
  ...
  
  ```
  
  **Tags:** plugin-development, users
  
  > **Comments:**
  > **username_1**: Posting as a comment, since this is off the top of my head... I think you want to set `authorId` of your entry to be the new user's id. Then, when you delete a user (through the control panel), it'll ask "What do you want to do with this person's content?"... at that point, you can just select "Delete it". If this actually helps you solve the problem, I'll post it as an official answer. :)  
  > **username_0**: BRILLIANT! I forgot all about that dialog - works perfectly! Update your comment to the answer and I'll mark it. Thanks username_1  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-04. Score: 2 | Accepted answer
  
  You'll want to set the `authorId` of your entry to be the *new user's id*.
  
  When you delete that user through the control panel, it'll ask "What do you want to do with this person's content?"... At that point, you can just select "Delete it".
  
  
  ---
  
  