- 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
Aliens are among us! And they're here in order to visit their human friends on the planet Earth. Build out the rest of this super secret app for the MIB so they can track different visitations by aliens and their human friends.
run bundle install
Create your migrations.
-
Aliens
should have aname
, aearth_disguise_name
, ahome_planet
, and alight_years_to_home_planet
-
Earthlings
should have afirst_name
, alast_name
and ajob
-
Visitations
should have adate
, analien_id
and anearthling_id
Column | Type |
---|---|
name | string |
earth_disguise_name | string |
home_planet | string |
light_years_to_home_planet | integer |
Column | Type |
---|---|
first_name | string |
last_name | string |
job | string |
Column | Type |
---|---|
date | string OR datetime |
alien_id | integer |
earthling_id | integer |
- What associations will this need?
- (i.e.
has_many
,has_many through
, andbelongs_to
)
Earthling#visitations
returns all the visitations for an earthlingEarthling#aliens
returns every alien that has visited that earthlingEarthling#full_name
returns the combination of the human's first name and last nameEarthling.filter_by_job(job)
takes in a job as a string and returns all earthlings with the specified job
Alien#visitations
returns all the visitations that alien has been involved inAlien#earthlings
returns every earthling the alien has visitedAlien#visit(earthling)
takes in an instance of an earthling and creates a visitation linking that earthling and alien for today's dateAlien#total_light_years_traveled
returns the light years from the alien's home planet multiplied by the number of visitations for that alien ... times two (because they have to travel both ways right?)Alien.most_frequent_visitor
returns the alien with the most visitationsAlien.average_light_years_to_home_planet
returns the average distance for all aliens to their home planets
Visitation#alien
returns the alien involved in the visitationVisitation#earthling
returns the earthling involved in the visitation