Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't understand the point of having a Log model if all you're doing is calculating attributes from other models. So I would set it up like so:</p> <pre><code>Class User # t.integer :weight (or if this can change regularly make this an attribute of meal and exercise so it's calculated and is logged specifically for those things) has_many :meals has_many :workouts has_many :exercises, through: :workouts class Meal # t.integer :carbs # t.integer :calories # t.integer :fat etc belongs_to :user class Workout belongs_to :user has_many :exercises class Exercise # t.integer :reps # t.integer :duration # t.integer :distance # t.integer :barbell_weight etc belongs_to :workout </code></pre> <p>So then these models are essentially the logs, and if you want to log things like 'calorie burn based on user weight', etc, then you can just dynamically create "log" type spreadsheets based on the calculations. If you want to know such calculations for each meal/exercise, then I would make user weight an attribute of meal and either exercise/workout so that you always know how many calories were burned at a particular time in a user's year-long fitness regime.</p> <p>EDIT based on comments:</p> <pre><code>class User has_many :logs class Log belongs_to :exercise belongs_to :user </code></pre> <p>if you also want to track meal logs in a similar way (as in, Meals are very different than the info being logged for them). then I'd do a polymorphic. But really, this is pretty specific to your situation, so you know your app the best and you need to make that decision.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload