Skip to content

Instantly share code, notes, and snippets.

@DakotaLMartinez
Last active November 7, 2020 19:25
Show Gist options
  • Save DakotaLMartinez/4ecb0693c56b5eed67ed76d04f63f1d5 to your computer and use it in GitHub Desktop.
Save DakotaLMartinez/4ecb0693c56b5eed67ed76d04f63f1d5 to your computer and use it in GitHub Desktop.
Rails Project Planning

What is the Many to many relationship and how is it used?

What is the User Submittable attribute on the join model?

What Validations do we need?

How do users fit into the application? How are they related to the other models?

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

Do we have Non Nested Versions of those nested routes?

What Scope Method(s) do we have and how are they used?

What does the schema for our app look like?

# table migration for: examples 
# t.string :name
# t.string :etc…
class Example 
	# relationships

	# validations 

	# user submittable attributes (if this is a join model)

	# scope_methods (if any)


end

Project Examples to flesh out:

  • Doctor, Patient and Appointment
  • User, Project, Task
  • Project, Programmer, Assignment
  • Recipe, Ingredient, RecipeIngredient
  • User, Exercise, ExerciseLog
  • User, Topic, Interest
  • User, Medication, Prescription
  • User, Movie, Review
  • Dancer, DanceClass, Enrollments
  • Character, Motivation, Alignment
@DakotaLMartinez
Copy link
Author

Doctor, Patient, Appointment

What is the Many to many relationship and how is it used?

Doctors <=> Patients, we have a view to display all of a doctor's patients and a view to display all of a patient's doctors:
/doctors/:doctor_id/patients
/patients/:patient_id/doctors

What is the User Submittable attribute on the join model?

Appointments have a start_time, end_time and location.

What Validations do we need?

Doctor must have a name, phone_number, specializations
Patients must have a name,
Appointments must have doctor_id, patient_id, start_time, end_time, location

How do users fit into the application? How are they related to the other models?

If a user is a parent, then how is it related to Doctor, Patient and Appointment,
user has_many :patients, has_many :doctors, through: :patients, user has_many :appointments, through: :patients
if a user was a receptionist, then how is it related to Doctor Patient, and Appointments
everything might belong to a user to make sure we don't see information related to other accounts.

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

/patients/:patient_id/doctors => all of that patient's doctors
/patients/:patient_id/appointments => all appointments made with that patient (the one who is identified by params[:patient_id])
/patients/:patient_id/appointments/new => a new appointment form with the patient pre-selected

Do we have Non Nested Versions of those nested routes?

/appointments => all appointments created by this user.
/appointments/new => a new appointment form where user must select the patient.

What Scope Method(s) do we have and how are they used? (class methods that return an ActiveRecord::Relation)

Appointment.past => appointments that have ended already.
Appointment.upcoming => appointments that haven't started yet.
in your appointments#index action, you could accept a query parameter for time and check whether it says "past" or "upcoming" and add that scope to the results as appropriate.
/appointments?time=past => We'll have the .past scope method added to our results
/appointments?time=upcoming => We'll have the .upcoming scope method added to our results

What does the schema for our app look like?

# table migration for: doctors 
# t.string :name
# t.string :phone_number
# t.string :specializations

class Doctor 
       # relationships
  has_many :appointments
  has_many :patients, through: :appointments

	# validations 
  validates :name, :phone_number, :specializations, presence: true
	# user submittable attributes (if this is a join model)
  
	# scope_methods (if any)


end

# table migration for: patients 
# t.string :name
# t.references :user

class Patient 
       # relationships
  belongs_to :user
  has_many :appointments
  has_many :doctors, through: :appointments

	# validations 
  validates :name, presence: true

end

# table migration for: appointments 
# t.references :doctor
# t.references :patient 
# t.datetime :start_time 
# t.datetime :end_time 
# t.string :location

class Appointment 
       # relationships
  belongs_to :doctor
  belongs_to :patient

	# validations 
  validates :doctor_id, :patient_id, :start_time, :end_time, :location, presence: true
	# user submittable attributes (if this is a join model) start_time, end_time and location
  
	# scope_methods (if any)
  # Appointment.past => appointments that have ended already.
  # Appointment.upcoming => appointments that haven't started yet.

end
# table migration for: users
# t.string :email 
# t.string :password_digest
class User 
  # relationships 
  has_many :patients 
  has_many :doctors, through: :patients 
  has_many :appointments, through: :patients
  # validations 

  
end

@patrick-rush
Copy link

patrick-rush commented Oct 23, 2020

User, Exercise, ExerciseLog

What is the Many to many relationship and how is it used?

User has_many Exercises
Exercise has_many Users
ExerciseLog belongs_to Users and Exercises

users/:user_id/exercises
exercises/:exercise_id/users

What is the User Submittable attribute on the join model?

Sets and Reps
Duration
Time (optional)

What Validations do we need?

User

  • Name
  • Password
  • Email

Exercise

  • Name

ExerciseLog

  • User
  • Exercise
  • Sets/Reps or Duration

How do users fit into the application? How are they related to the other models?

User is the one logging exercises. In this case, Users will only see their own exercise logs.

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

exercises/:exercise_id/exerciselogs -> all of the logs the currently logged in user has made for that particular exercise

exercises/:exericse_id/exerciselogs/new -> a form to create a new exercise log for that particular exercise
resources :exercises do
resources :exercise_logs, only[:index, :new]
end

Do we have Non Nested Versions of those nested routes?

exerciselogs/new -> might be useful if the app is for a trainer, they can log exercises for their clients
exercises/new
exerciselogs

What Scope Method(s) do we have and how are they used?

how many users did an exercise
ExerciseLog.how_many_users(:exercise_id) => number of users
Exercise.total(:exercise_id) => if duration, time or if sets/reps, how many reps
IF exercise has a category, then Exercise.type(:category) => HIIT, cardio, yoga, dance, barre, weight lifting, etc.

ExerciseLog.long -> all logs where duration is longer than 30 minutes
ExerciseLog.last_week -> all logs made at a time greater than 1 week ago.

What does the schema for our app look like?

# table migration for: users
# t.string :name
# t.string :password_digest
# t.string :email 

class User 
	# relationships
  has_many :exercise_logs
  has_many :exercises, through: :exercise_logs
	# validations 
  validates :name, :password, :email 
	# user submittable attributes (if this is a join model)

	# scope_methods (if any)

end

# table migration for: exercises
# t.string :name
# t.string :category

class Exercise 
	# relationships
  has_many :exercise_logs
  has_many :users, through: :exercise_logs
	# validations 
  validates :name 
	# user submittable attributes (if this is a join model)

	# scope_methods (if any)
  Exercise.total(:exercise_id) => if duration, time or if sets/reps, how many reps
end

# table migration for: exercise_logs
# t.integer :sets
# t.integer :reps
# t.integer :duration
# t.references :user (t.references <- pass a symbol of the class name and it will produce foreign keys)
# t.references :exercise 

class ExerciseLog
	# relationships
  belongs_to :user 
  belongs_to :exercise 
	# validations 
  validates :exercise_id, :user_id, either :sets && :reps || :duration (I know that's not how you do that)
	# user submittable attributes (if this is a join model)
  sets/reps OR duration
	# scope_methods (if any)
  ExerciseLog.how_many_users(:exercise_id) => number of users
end

Thanks Rumiko and Mitzi :)

@DakotaLMartinez
Copy link
Author

users/:user_id/exerciselogs/new

It probably doesn't make sense to have this route because a User shouldn't be able to create an exercise log that belongs to another user. I might use this one instead:
/exercises/:exercise_id/exercise_logs/new

@DakotaLMartinez
Copy link
Author

User, Project, Task

What is the Many to many relationship and how is it used?

User <=> Project (through task)
many to many always requires 6 macros:

  1. Each of the many to many models has many of the join model, and then many of the other through the join
  2. The join model belongs to both of the others.
User has_many :tasks
User has_many :projects, through: :tasks
Project has_many :tasks
Project has_many :users, through: :tasks
Task belongs_to :user
Task belongs_to :project

Project belongs_to :creator, class_name: "User"
User has_many :created_projects, class_name: "Project", foreign_key: :creator_id

We'll have a view that can display all of the projects a user has been assigned tasks for.
We'll also have a view that can display all of the users who have been assigned tasks for a project.

What is the User Submittable attribute on the join model?

Tasks have Description and Status

What Validations do we need?

see below

How do users fit into the application? How are they related to the other models?

Users are in domain so that's a little bit more self explanatory here. Users are able to create tasks and projects and (maybe?) see other user's tasks that are related to projects they're also involved in.

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

/users/:user_id/tasks/new => form to add a task assigned to a particular user (the one with the params[:user_id]) and you would select the project to assign it to.
/users/:user_id/tasks => a list of tasks that belong to that user
/projects/:project_id/tasks/new => form to add a task assigned to a particular project (the one with the params[:project_id]) and you would select the user to assign it to.
/projects/:project_id/tasks => a list of tasks that belong to that project
/projects/:project_id/users/:user_id/tasks => Shows a list of all a particular user's tasks on a particular project

Do we have Non Nested Versions of those nested routes?

/tasks => a list of all of the tasks assigned to the current user
/tasks/new => a form that allows you to create a task and select both the project and the user to assign it to.

What Scope Method(s) do we have and how are they used?

Task.incomplete => returns tasks with a status of "Not started" or "In Progress"
Task.complete => returns completed tasks
User.no_current_tasks => returns users who have no incomplete tasks.
User.few_current_tasks => returns users who have less than or equal to 3 incomplete tasks
Project.in_progress => Projects where the status is "In Progress"
Project.complete => Projects where the status is "Complete"
Project.icebox => Projects with no start_date and no due_date

What does the schema for our app look like?

# table migration for: projects 
# t.string :name
# t.string :description
# t.integer :creator_id
# t.datetime :start_date
# t.datetime :due_date
# t.string :status
class Project 
	# relationships
	has_many :tasks
	has_many :users, through: :tasks
	# validations 
	# must have a name and description. Maybe validate that start_date is not in the past (if it's present and also isn't after the due_date)

	# scope_methods (if any)
	# Project.in_progress => Projects where the status is "In Progress"
	# Project.complete => Projects where the status is "Complete"
	# Project.icebox => Projects with no start_date and no due_date

end

# table migration for: users 
# t.string :username
# t.string :password_digest
class User 
	# relationships
	has_many :tasks
	has_many :projects, through: :tasks
	# validations 
	# must have a unique username that is present


	# scope_methods (if any)
	# User.no_current_tasks => returns users who have no incomplete tasks.
	# User.few_current_tasks => returns users who have less than or equal to 3 incomplete tasks
end 
# table migration for: Task 
# t.string :description
# t.string :status
# t.integer :user_id
# t.integer :project_id
class Task 
	# relationships
	belongs_to :user
	belongs_to :project
	# validations 
	# description and status must be present, status must be included in ["not started", "in progress", "complete"]
	# user submittable attributes (if this is a join model)
	# description and status
	# scope_methods (if any)
	# Task.incomplete => returns tasks with a status of "Not started" or "In Progress"
	# Task.complete => returns completed tasks
end

@DakotaLMartinez
Copy link
Author

What is the Many to many relationship and how is it used?

Student <=> Allergy
Always 6 Macros:

Student has_many :student_teachers
Student has_many :teachers, through: :student_teachers
StudentTeacher belongs_to :student
StudentTeacher belongs_to :teacher
Teacher has_many :student_teachers
Teacher has_many :students, through: :student_teachers

Student has_many :student_allergies 
Student has_many :allergies, through: :student_allergies
StudentAllergy belongs_to :student 
StudentAllergy belongs_to :allergy
Allergy has_many :student_allergies
Allergy has_many :students, through: :student_allergies

Users can view the students associated with a teacher.
Teachers can see all of their students' allergies (with severity)
Teachers can see all of the students that have a particular allergy (/allergies/:allergy_id/students => all of the students that have that allergy)

What is the User Submittable attribute on the join model?

StudentTeacher has year, and/or StudentAllergy has severity

What Validations do we need?

see below

How do users fit into the application? How are they related to the other models?

User is a teacher who logs in and adds students to their class and also their allergies.

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

/teachers/:teacher_id/students => list of students who have teacher_id of params[:teacher_id]
/students/:student_id/student_allergies => student_allergies index with severity for particular student with id of params[:student_id]
/students/:student_id/student_allergies/new => form to add a student allergy for the student with id params[:student_id] (form comes prefilled with student need to select allergy and fill in severity)

Do we have Non Nested Versions of those nested routes?

/student_allergies/new => form to add an allergy to a student (need to select both student and allergy

What Scope Method(s) do we have and how are they used?

Allergy.severe => all severe allergies
teachers.allergies.severe => All

What does the schema for our app look like?

# table migration for: teachers 
# t.string :first_name
# t.string :last_name
# t.string :email
# t.string :password_digest
# t.string :etc…
class Teacher 
	# relationships
	has_many :student_teachers
	has_many :students, through: :student_teachers
	has_many :current_students,-> {where(student_teachers: {year: Time.now.year})}, through: :student_teachers
	has_many :allergies, through: :students
	# validations 
	# must have first_name, last_name
	# must have email that's unique
	# user submittable attributes (if this is a join model)

	# scope_methods (if any)


end

# table migration for: student_teachers 
# t.references :student
# t.references :teacher
# t.integer :year
class StudentTeacher 
	# relationships
	belongs_to :student 
	belongs_to :teacher
	# validations 
	# year has to be present
	# year numericality validation must be after 1900?
	# student_id uniquess scoped to year
	# user submittable attributes (if this is a join model)
	## year
	# scope_methods (if any)


end

# table migration for: students 
# t.string :first_name
# t.string :last_name
# t.string :guardian_1
# t.string :guardian_2
# t.string :guardian_contact_info
class Student 
	# relationships
	has_many :student_teachers
	has_many :teachers, through: :student_teachers
	has_many :current_teachers,-> {where(student_teachers: {year: Time.now.year})}, through: :student_teachers
	has_many :student_allergies
	has_many :allergies, through: :student_allergies
	# validations 
	# first_name, last_name, guardian_1, contact_info must be present

	# scope_methods (if any)
	def self.has_severe_allergy
		includes(:student_allergies).where(student_allergies: {severity: 'severe'})
	end
	# I could do something like 
	# @students_with_severe_allergy = @teacher.students.has_severe_allergy
	# @students_with_severe_allergy.each do |student|
	#	student.allergies.severe.each do |allergy|
	#		<%= student.name %> has a severe <%= allergy.name %> allergy
	#	end
	# end

end

# table migration for: allergies 
# t.string :name
# t.string :etc…
class Allergy 
	# relationships
	has_many :student_allergies
	has_many :students, through: :student_allergies
	# validations 
	validates :name, presence and uniqueness
	# user submittable attributes (if this is a join model)

	# scope_methods (if any)
	def self.severe 
		includes(:student_allergies).where(student_allergies: {severity: 'severe'})
	end

end

# table migration for: student_allergies 
# t.references :student
# t.references :allergy
# t.string :severity
class StudentAllergy 
	# relationships
	belongs_to :student
	belongs_to :allergy
	# validations 
	# severity must be present
	# user submittable attributes (if this is a join model)
	## severity
	# scope_methods (if any)
	def self.severe
		where(severity: 'severe')
	end

	def self.mild
		where(severity: 'mild')
	end

	def self.moderate 
		where(severity: 'moderate')
	end
end

@ty-raino
Copy link

ty-raino commented Nov 6, 2020

What is the Many to many relationship and how is it used?

Users -< Reviews >- Games

What is the User Submittable attribute on the join model?

  • Rating
  • Content

What Validations do we need?

Users

  • Username
  • Email
  • Password

Reviews

  • Rating
  • Content

Comments

  • Content

Games

  • Title

How do users fit into the application? How are they related to the other models?

Users can:

  • Review games
  • Add games
  • Comment on other user's reviews
  • Upvote or Downvote other user's reviews (maybe)

Relationships:

  • User has many Reviews
  • User has many Comments
  • User has many Votes
  • User has many Games through Reviews

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

games/game_id/reviews => to view all of the reviews made for that specific game
(to be populated...)

Do we have Non Nested Versions of those nested routes?

(to be populated...)

What Scope Method(s) do we have and how are they used?

(to be populated...)

What does the schema for our app look like?

# table migration for: users 
# t.string :username
# t.string :email
# t.string :password_digest

class Users 
	# relationships
	has_many :reviews
	has_many :comments
	has_many :votes
	has_many :games, through: :reviews
	# validations 
	validations :username, presence: true, uniqueness: true
	validations :email, presence: true, uniqueness: true, 
	# scope_methods (if any)
	(to be populated...)
end
# table migration for: reviews 
# t.integer :user_id
# t.integer :game_id
# t.string :rating
# t.string :content

class Reviews 
	# relationships
	belongs_to :user
	belongs_to :game
	# validations 
	validates :rating, presence: true
	validates :rating, :inclusion => { :in => 1..5, :message => " should be between 1 to 5" }
	validates :content, presence: true, length: { maximum: 130 }
	# user submittable attributes (if this is a join model)
	Rating and Content
	# scope_methods (if any)
	(to be populated...)
end
# table migration for: comments 
# t.integer :user_id
# t.integer :review_id
# t.string :content
class Comments 
	# relationships
	belongs_to :users
	belongs_to :reviews
	# validations 
	validates :content, presence: true, length: { maximum: 50 }
end
# table migration for: games 
# t.string :title
class Games 
	# relationships
	has_many :reviews
	has_many :users, through: :reviews
	# validations 
	validates :title, presence: true, uniqueness: true
	validates :title, length: { maximum: 35 }
	validates :is_title_case (custom validation coming soon)
	# scope_methods (if any)
	(to be populated...)
end

Project Examples to flesh out:

  • Doctor, Patient and Appointment
  • User, Project, Task
  • Project, Programmer, Assignment
  • Recipe, Ingredient, RecipeIngredient
  • User, Exercise, ExerciseLog
  • User, Topic, Interest
  • User, Medication, Prescription
  • User, Movie, Review
  • Dancer, DanceClass, Enrollments
  • Character, Motivation, Alignment

@HopperMCS
Copy link

HopperMCS commented Nov 7, 2020

@DakotaLMartinez please review, I've started it but need help finishing/making sure this even works to begin with

What is the Many to many relationship and how is it used?

Users <> Libraries through Performance Ratings
library.users && user.libraries - not created, just rated

What is the User Submittable attribute on the join model?

  • Performace Rating

What Validations do we need?

  • Users

    • Username, presence uniq
    • Email - presence, uniq
    • Password - length, presence
  • Libraries

    • Name
    • language_id
    • Link to source
  • Language

    • Name
    • Purpose
    • Compiled/Scripted?
    • Turing complete?
  • Performance Rating

    • Rating
    • Commentary
    • belongs to user, user_id
    • belongs to libraires, library_id

How do users fit into the application? How are they related to the other models?

  • Users can:
    • Add languages
    • Add libraries
    • Add performance ratings to libraries

What are our Nested Routes? (We need a nested new route and either a nested index or nested show route)

languages/language_id/libraries - nested index - shows libraries specific to language_id
languages/language_id/libraries/new - nested new - form to create lib with lang preset

Do we have Non Nested Versions of those nested routes?

/libraries/ - shows all libraries
/libraries/new - form to create lib without preset lang

What Scope Method(s) do we have and how are they used?

  • order by psoitive/negative
  • order by created_at

What does the schema for our app look like?

# table migration for: examples 
# t.string :name
# t.string :etc…
class Example 
	# relationships

	# validations 

	# user submittable attributes (if this is a join model)

	# scope_methods (if any)


end

Project Examples to flesh out:

Doctor, Patient and Appointment
User, Project, Task
Project, Programmer, Assignment
Recipe, Ingredient, RecipeIngredient
User, Exercise, ExerciseLog
User, Topic, Interest
User, Medication, Prescription
User, Movie, Review
Dancer, DanceClass, Enrollments
Character, Motivation, Alignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment