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

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