TheIronYard--Orlando / ROR--2015--SPRING

Resources and homework for the Ruby on Rails cohort at @TheIronYard--Orlando for Spring 2015
Creative Commons Zero v1.0 Universal
6 stars 7 forks source link

13 -- ActiveRecord -- Jeff Winkler #111

Closed palmbeachjeff closed 4 years ago

palmbeachjeff commented 9 years ago
palmbeachjeff commented 9 years ago

Wiki

palmbeachjeff commented 9 years ago

Forgot to push, so here is Rails using Active Record: Team.where(division: 'North', conference:'NFC').map{|team| team.name}

--Select every team from the NFC North

Team.where('wins >= 11').map{|team| team.name}

Select every team with at least 11 wins

Team.where("wins >= 8 AND playoff = 0").map{|team| team.name}

Select every team with at least 8 wins that did not make the playoffs

Team.where('wins <= 5').map{|team| team.name}

Rename every team with fewer than 4 wins "Losers"

LOOK FOR WAY TO .UPDATE_ALL TO CHANGE TO "LOSERS"

Team.joins(:city).where("population_2013 < 5000000").map{|team| team.name + ", " + city.team.name}

--Select every team that plays in a city of fewer than 5 million people,

and the name of the city

Select every AFC team that plays in a city that is shrinking in population

City.joins(:teams).map{|city| city.name}

Select every city that has a team

State.joins(:teams).map{|state| state.name}