Lily-Brown / bandapp

BandWagon is an application that allows bands and musicians to find each other.
https://hop-on-the-bandwagon.herokuapp.com
0 stars 1 forks source link

refactor to use object oriented methods: `band.openings` and `band.members` #32

Open nathanallen opened 8 years ago

nathanallen commented 8 years ago

get_openings and get_members feels like the kind of thing a band knows about the world.

Refactor to use object oriented methods: band.openings and band.members

See bands_controller#L69-L75 & band_instrument_musicians_controller.rb#L41-L43

Lily-Brown commented 8 years ago

Fixes issue in Pull Request #42 for Band Controller. Band_Instrument_Musician Controller remains same.

nathanallen commented 8 years ago

Naming things is hard! As submitted your members is actually memberships (e.g. band_instrument_musicans instead of musicians). Which do we want?

nathanallen commented 8 years ago

Refactor:

  # /models/band.rb
  def openings
    BandInstrumentMusician.all.where({musician_id: nil})
  end
  # /bands_controller.rb
     @openings = @band.openings.all.where(band_id: @band.id)

Merged together this becomes:

BandInstrumentMusician.all.where({musician_id: nil}).all.where(band_id: @band.id)

Which in translation is:

# for a given band, find me all the openings:
band.band_instrument_musicians.where({musician_id: nil})
Lily-Brown commented 8 years ago

@nathanallen Yes!! We were having trouble chaining those together before! Thanks for the help! Works great!