We have three models: House, Owner, and Project
For our purposes, a House has many Projects, an Owner has many Projects,
and a Project belongs to an Owner and to a House.
House - Owner 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.
- Active Record Migrations
- Active Record Associations
- Class and Instance Methods
- Active Record Querying
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!
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.
The starter code has migrations and models for the initial House and Owner
models, and seed data for some Houses and Owners.
You will need to create the migration for the projects table using the attributes specified in the deliverables below.
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.
Before working on the rest of the deliverables, you will need to create a
migration for the projects table.
- A
Projectbelongs to aOwner, and aProjectalso belongs to aHouse. In your migration, create any columns yourprojectstable will need to establish these relationships using the right foreign keys. - The
projectstable should also have:- A
pricecolumn that stores an integer.
- A
After creating the projects table using a migration, use the seeds.rb file to
create instances of your Project class so you can test your code.
Once you've set up your projects table, work on building out the following
deliverables.
Use Active Record association macros and Active Record query methods where
appropriate (i.e. has_many, has_many through, and belongs_to).
Project#owner- returns the
Ownerinstance for this Project
- returns the
Project#house- returns the
Houseinstance for this Project
- returns the
House#projects- returns a collection of all the projects for the House
House#owners- returns a collection of all the owners who have projects for the House
Owner#projects- returns a collection of all the projects that the Owner has done
Owner#houses- returns a collection of all the houses that the Owner has projects for
Use rake console and check that these methods work before proceeding. For
example, you should be able to call Owner.first.houses and see a list of the
houses for the first owner in the database based on your seed data; and
Project.first.owner should return the owner for the first project in the database.
-
House.oldest_house- should return the oldest house
-
House.get_houses_with_solar- should return a collection of houses that have solar installed
-
House#install_solar- if house doesn't have solar, update it's
solarattribute. If the house already has solar,putsout "This house already has solar installed"
- if house doesn't have solar, update it's
-
House#schedule_project(owner, price)- takes an
owner(an instance of theOwnerclass) and a price as arguments, and create a newProjectinstance associated with this house and the given owner
- takes an
-
House#total_remodeling_cost- should retrun the total price of all the projects associated with this house
-
Owner#schedule_project(house, price)- takes a
house(an instance of theHouseclass) and a price as arguments, and create a newProjectinstance associated with this owner and the given owner
- takes a
-
Owner#total_cost_of_all_projects- should return the total cost for all the owner's projects
-
Owner#list_of_all_states- should return a collection of unique strings for all states the
ownerhas ahousein
- should return a collection of unique strings for all states the
-
Project.total_cost- should return the total cost of all
projects
- should return the total cost of all
-
Project#install_solar_and_update_price_by_500- if house already has solar installed
puts"You're good to go." - If house doesn't have solar, update the solar attribute to true, increase the project's price by 500, and
putsout"Solar added to this project. The new price is #{new project price}"
- if house already has solar installed