Open nathanallen opened 8 years ago
Fixes issue in Pull Request #42 for Band Controller. Band_Instrument_Musician Controller remains same.
Naming things is hard! As submitted your members
is actually memberships
(e.g. band_instrument_musicans instead of musicians). Which do we want?
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})
@nathanallen Yes!! We were having trouble chaining those together before! Thanks for the help! Works great!
get_openings
andget_members
feels like the kind of thing aband
knows about the world.Refactor to use object oriented methods:
band.openings
andband.members
See bands_controller#L69-L75 & band_instrument_musicians_controller.rb#L41-L43