Answers.Body: <p>There are a whole bunch of ways to do what you want to do.</p>
  
  <p>You can add custom fields to user accounts. If you wanted to go with option 2 then you could create a custom text field and write the JSON into that.</p>
  
  <p>Another way would be to add a Matrix field to the user accounts and write a new row for each workout.</p>
  
  <p>And another way would be to create a new channel for Workouts. When a user completes a workout, a new entry is created and related to them. You can then retrieve entries relating to that user to display their workout history.</p>
  
  <p>And yet another way, would be to create a custom model for a Workout and relate it to the user account. Your plugin would then create records using that model and you could retrieve them to display the user's progress.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-30T15:26:09.153Z
Answers.LastActivityDate: 2018-11-30T15:26:09.153Z
Answers.UserDisplayName: foamcow
Answers.Body: <p>I'm in a VERY similar situation .... my reputation is too low to comment so had to add as answer - I hope that isn't a problem.</p>
  
  <p>Our system interacts with a 3rd party web app.  Records are created in the 3rd party app and we need to keep references to them in Craft.  Each record is tied to a USER.  For each record we need to store the relevant recordId and JSON data in Craft.   There will be 100+ records for each user and each record will contain roughly 50KB of data.</p>
  
  <p>I'm debating which of the following suggestions from foamcow's answer is better.  Specifically I was debating:</p>
  
  <p>1) store in matrix field:
  create a matrix field (two fields = recordId; json) and assign this to the user;
  create a new 'block' each time a new record needs to be store;</p>
  
  <p>vs.</p>
  
  <p>2) store in Entries
  create a new Entry (section type = Channel?);
  create a new entry each time a record needs to be stored</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-20T06:01:34.117Z
Answers.LastActivityDate: 2019-10-20T06:01:34.117Z
Answers.UserDisplayName: Erant
Body: <p>I need some direction in how to store (complex) data into users (best practice)</p>
  
  <p>I'm working on a project for a fitness app. I created a structure with 2 levels for workouts where level 1 entries are skills and level 2 entries progressions for these skills, in the progressions I made a matrix containing a content field for an exercise, a table for data such as sets and reps and some practical information. </p>
  
  <p>Now here is how it should work:</p>
  
  <p>The user starts a workout, a workout contains 4 or more exercises to complete for the workout to be finished. Now when every set of an exercise is done, the user has to fill in a number of repetitions he/she did for every set. When the workout finishes I would like to save all this data in the user (Or should i make a section for this?)</p>
  
  <p>The data looks something like this:</p>
  
  <pre><code>    "skillID": {
        "set1":"rep1"
        "set2":"rep2"
      }, etc
  </code></pre>
  
  <p>This data is important, the next time this user is logging in and starting a workout I want to retrieve this data to give the user overview of how he/she is progressing, so like comparing the workout data with the user data. Plus it should be some kind of history too. Here it gets a bit to complicated for me, but I want to learn this! My thoughts were this:</p>
  
  <p>Option 1: I create a section, here I create user data entries (so they are related with the user who create them) I store the data somehow on these entries, with tables or something
  Option 2: I store 2 JSON models into the user (if possible), 1 for writing and overwriting the progress of each workout (when doing the same workout it overwrites the existing data) and 1 for the history, were every date of doing a workout is a key and the value is the whole workout data provided by the users input.</p>
  
  <p>What is the best way to go?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-01T22:51:59.653Z
Comments.Text: Kevon, did you ever choose a path for this functionality and do you have any recommendations now that you've had a go at it?  We're evaluating Craft as a potential platform for an upcoming project, and we have very similar needs!
Comments.UserDisplayName: Keith
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-06T15:52:04.797Z
Comments.Text: Hi Keith, sorry for the late comment but i was working on *real work projects so i didn't got the time to procceed on this! But, I needed the same thing and went for the JSON option stored on the users custom field! So for my app i'm going to take the same approach, I maybe want to share the data with other applications so JSON was my best choice! And what can I say, if you go with Craft you will be happy on how everything works! It's just AMAZING :) Good luck!
Comments.UserDisplayName: Kevon
Tags: <plugin-development><craft3><users><json><custom-field>
Title: How to store custom data into a user
ThreadText: # How to store custom data into a user
  
  (Asked by: username_0 on 2018-11-29)
  
  I need some direction in how to store (complex) data into users (best practice)
  
  I'm working on a project for a fitness app. I created a structure with 2 levels for workouts where level 1 entries are skills and level 2 entries progressions for these skills, in the progressions I made a matrix containing a content field for an exercise, a table for data such as sets and reps and some practical information.
  
  Now here is how it should work:
  
  The user starts a workout, a workout contains 4 or more exercises to complete for the workout to be finished. Now when every set of an exercise is done, the user has to fill in a number of repetitions he/she did for every set. When the workout finishes I would like to save all this data in the user (Or should i make a section for this?)
  
  The data looks something like this:
  
  ```
      "skillID": {
        "set1":"rep1"
        "set2":"rep2"
      }, etc
  
  ```
  
  This data is important, the next time this user is logging in and starting a workout I want to retrieve this data to give the user overview of how he/she is progressing, so like comparing the workout data with the user data. Plus it should be some kind of history too. Here it gets a bit to complicated for me, but I want to learn this! My thoughts were this:
  
  Option 1: I create a section, here I create user data entries (so they are related with the user who create them) I store the data somehow on these entries, with tables or something
  Option 2: I store 2 JSON models into the user (if possible), 1 for writing and overwriting the progress of each workout (when doing the same workout it overwrites the existing data) and 1 for the history, were every date of doing a workout is a key and the value is the whole workout data provided by the users input.
  
  What is the best way to go?
  
  **Tags:** plugin-development, craft3, users, json, custom-field
  
  > **Comments:**
  > **username_1**: username_0, did you ever choose a path for this functionality and do you have any recommendations now that you've had a go at it?  We're evaluating Craft as a potential platform for an upcoming project, and we have very similar needs!  
  > **username_0**: Hi username_1, sorry for the late comment but i was working on *real work projects so i didn't got the time to procceed on this! But, I needed the same thing and went for the JSON option stored on the users custom field! So for my app i'm going to take the same approach, I maybe want to share the data with other applications so JSON was my best choice! And what can I say, if you go with Craft you will be happy on how everything works! It's just AMAZING :) Good luck!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-11-30. Score: 3 | Accepted answer
  
  There are a whole bunch of ways to do what you want to do.
  
  You can add custom fields to user accounts. If you wanted to go with option 2 then you could create a custom text field and write the JSON into that.
  
  Another way would be to add a Matrix field to the user accounts and write a new row for each workout.
  
  And another way would be to create a new channel for Workouts. When a user completes a workout, a new entry is created and related to them. You can then retrieve entries relating to that user to display their workout history.
  
  And yet another way, would be to create a custom model for a Workout and relate it to the user account. Your plugin would then create records using that model and you could retrieve them to display the user's progress.
  
  
  ---
  
  ### Answer by username_3 on 2019-10-20. Score: 1
  
  I'm in a VERY similar situation .... my reputation is too low to comment so had to add as answer - I hope that isn't a problem.
  
  Our system interacts with a 3rd party web app. Records are created in the 3rd party app and we need to keep references to them in Craft. Each record is tied to a USER. For each record we need to store the relevant recordId and JSON data in Craft. There will be 100+ records for each user and each record will contain roughly 50KB of data.
  
  I'm debating which of the following suggestions from username_2's answer is better. Specifically I was debating:
  
  1) store in matrix field:
  create a matrix field (two fields = recordId; json) and assign this to the user;
  create a new 'block' each time a new record needs to be store;
  
  vs.
  
  2) store in Entries
  create a new Entry (section type = Channel?);
  create a new entry each time a record needs to be stored
  
  
  ---
  
  