Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed, I think #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

jonahroth
Copy link

@kmodlich @maxdignan I changed one line of the "don't change" part because otherwise the associations kept getting stored as nil, and that one change (storing an id instead of the entire object) makes the code much more understandable without significantly changing what it does

@maxdignan
Copy link

This is one of the more challenging tasks on PairColumbus, but it looks like this is a solid solution.

class Booking < ActiveRecord::Base
#insert our associations here
def bookings
Booking.where(:room => rooms.map{|r| r.id})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you don't need to map the rooms to their ids. ActiveRecord probably handles this the same:

Booking.where(:room => rooms)

Better yet, let ActiveRecord handle the whole thing:

has_many :bookings, through: :rooms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants