Coder Social home page Coder Social logo

phase-3-mock-code-challenge-freebie-tracker's Introduction

Phase 3 Active Record Mock Code Challenge: Freebie Tracker

Learning Goals

  • Write Active Record Migrations
  • Connect between tables using Active Record Associations
  • Write class and instance methods using Active Record
  • Use Active Record to query the database

Introduction

For this assignment, we'll be working with a freebie domain.

As developers, when you attend hackathons, you'll realize they hand out a lot of free items (informally called freebies, or swag)! Let's make an app for developers that keeps track of all the freebies they obtain.

We have three models: Company, Dev, and Freebie

For our purposes, a Company has many Freebies, a Dev has many Freebies, and a Freebie belongs to a Dev and to a Company.

Company - Dev is a many to many relationship.

Note: You should draw your domain on paper or on a whiteboard before you start coding. Remember to identify a single source of truth for your data.

Instructions

To get started, run bundle install while inside of this directory.

Build out all of the methods listed in the deliverables. The methods are listed in a suggested order, but you can feel free to tackle the ones you think are easiest. Be careful: some of the later methods rely on earlier ones.

Remember! This code challenge does not have tests. You cannot run rspec and you cannot run learn test. You'll need to create your own sample instances so that you can try out your code on your own. Make sure your associations and methods work in the console before submitting.

We've provided you with a tool that you can use to test your code. To use it, run rake console from the command line. This will start a pry session with your classes defined. You can test out the methods that you write here. You are also encouraged to use the seeds.rb file to create sample data to test your models and associations.

Writing error-free code is more important than completing all of the deliverables listed - prioritize writing methods that work over writing more methods that don't work. You should test your code in the console as you write.

Similarly, messy code that works is better than clean code that doesn't. First, prioritize getting things working. Then, if there is time at the end, refactor your code to adhere to best practices.

Before you submit! Save and run your code to verify that it works as you expect. If you have any methods that are not working yet, feel free to leave comments describing your progress.

What You Already Have

The starter code has migrations and models for the initial Company and Dev models, and seed data for some Companys and Devs. The schema currently looks like this:

companies Table

Column Type
name String
founding_year Integer

devs Table

Column Type
name String

You will need to create the migration for the freebies table using the attributes specified in the deliverables below.

Deliverables

Write the following methods in the classes in the files provided. Feel free to build out any helper methods if needed.

Deliverables use the notation # for instance methods, and . for class methods.

Remember: Active Record give your classes access to a lot of methods already! Keep in mind what methods Active Record gives you access to on each of your classes when you're approaching the deliverables below.

Migrations

Before working on the rest of the deliverables, you will need to create a migration for the freebies table.

  • A Freebie belongs to a Dev, and a Freebie also belongs to a Company. In your migration, create any columns your freebies table will need to establish these relationships using the right foreign keys.
  • The freebies table should also have:
    • An item_name column that stores a string.
    • A value column that stores an integer.

After creating the freebies table using a migration, use the seeds.rb file to create instances of your Freebie class so you can test your code.

Once you've set up your freebies table, work on building out the following deliverables.

Object Association Methods

Use Active Record association macros and Active Record query methods where appropriate (i.e. has_many, has_many through, and belongs_to).

Note: The plural of "freebie" is "freebies" and the singular of "freebies" is "freebie".

Freebie

  • Freebie#dev
    • returns the Dev instance for this Freebie
  • Freebie#company
    • returns the Company instance for this Freebie

Company

  • Company#freebies
    • returns a collection of all the freebies for the Company
  • Company#devs
    • returns a collection of all the devs who collected freebies from the Company

Dev

  • Dev#freebies
    • returns a collection of all the freebies that the Dev has collected
  • Dev#companies
    • returns a collection of all the companies that the Dev has collected freebies from

Use rake console and check that these methods work before proceeding. For example, you should be able to call Dev.first.companies and see a list of the companies for the first dev in the database based on your seed data; and Freebie.first.dev should return the dev for the first freebie in the database.

Aggregate and Association Methods

Freebie

  • Freebie#print_details
    • should return a string formatted as follows: {insert dev's name} owns a {insert freebie's item_name} from {insert company's name}

Company

  • Company#give_freebie(dev, item_name, value)
    • takes a dev (an instance of the Dev class), an item_name (string), and a value as arguments, and creates a new Freebie instance associated with this company and the given dev
  • Company.oldest_company
    • returns the Company instance with the earliest founding year

Dev

  • Dev#received_one?(item_name)
    • accepts an item_name (string) and returns true if any of the freebies associated with the dev has that item_name, otherwise returns false
  • Dev#give_away(dev, freebie)
    • accepts a Dev instance and a Freebie instance, changes the freebie's dev to be the given dev; your code should only make the change if the freebie belongs to the dev who's giving it away

phase-3-mock-code-challenge-freebie-tracker's People

Contributors

ccmilla avatar ihollander avatar lizbur10 avatar lsamano avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phase-3-mock-code-challenge-freebie-tracker's Issues

Dev#give_away(dev, freebie) is confusing

Thanks for raising this issue! Future learners thank you for your diligence. In
order to help the curriculum team address the problem, please use this template
to submit your feedback. We'll work on addressing the issue as soon as we can.

Please fill out as much of the information below as you can (it's ok if you
don't fill out every section). The more context we have, the easier it will be
to fix your issue!

Note: you should only raise issues related to the contents of this lesson.
If you have questions about your code or need help troubleshooting, reach out to
an instructor/your peers.


Link to Canvas

https://learning.flatironschool.com/courses/4214/assignments/135716?module_item_id=281561

What should be changed?

Move Dev#give_away to Freebie#give_away (?)

Additional context

The last deliverable is confusing. There is no logical connection between the dev instance that #give_away is called on the and freebie instance that they are giving_away. In other words, a freebie doesn't need to belong_to the dev who is giving it to another dev. Some students found this illogical (and immoral :) ) and struggled to find or create some connection between the dev instance #give_away is called on and the dev the freebie belongs_to.

If #give_away were a method on a Freebie instance, it would be straightforward to update the :dev_id on it without the logical hiccup of a dev being able to give anyone's freebie to anyone else.

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.