GithubHelp home page GithubHelp logo

ar_school's Introduction

AR-Environment-Skeleton

You can use this repo to build new Activerecord projects

  • You will need to create your own app/models directories

Additional Deliverables

Changing to Many-to-Many

  • What changes did you make to your app? Why?

I did the remapping so that I could visually see what the new changes are.

I removed the grade_level_id columm in the teachers and students tables because GradeLevel is a now a class and instances of Teacher and Student belong to GradeLevel.

I removed the teacher_id column from the students table because changed from a has-many/belongs to association to a has-many-through association.

I created the join class model and table, GradeLevel and grade_levels respectively to reflect the new deliverables. The table was created so that it could hold students and teachers foreign keys

For macro associations, I changed the Teacher and Student classes because I needed to show that they don't have a direct or one-to-many assocation any more. The have an association through a join table.

    has_many :grade_levels
    has_many :students, through: :grade_levels
    has_many :grade_levels
    has_many :teachers, through: :grade_levels

Similarly, I added the macro association to the GradeLevel class so that instances of the Student class can access the information about Teacher class instances that are have relationship by being within the same row on the grade_levels table.

    belongs_to :student
    belongs_to :teacher

I also added ActiveRecord::Base inheritance to GradeLevel class so that the class can inherit the built-in methods that ActiveRecord has.

I edited and refactored the seed file to reflect change in associations. Otherwise there would have been argument error issues with providing more information than Ruby expected.

Additionally, I created assocation methods Teacher#students and Student#teachers because particular Student instances should know the Teacher instances that they're assocaited within grade_levels and vice versa with Teachers instance and Student instances. I also created GradeLevel.students and GradeLevel.teachers for any future class method deliverables that might require having a list of all teacher instances and student instances.

Additional Relationship

Write down deliverables for that relationship (what attributes? What class methods? What instance methods?) and then send them to me.

Questions

  • Which method(s) does Active Record create for you?

    Active Record has the .all method built-in. We can also call on the attributes of our class instances like first_name and last_name because that is stored in our database and just like in OO with attr_accessors and attr_readers, we can access that information to return a certain value.

  • Which method(s) did you have to create yourself? Why?

    I had to create the Teacher#tenure and the Student.all_in_grade methods.

ar_school's People

Contributors

abeciana1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.