Hotel has_many :rooms, and has_many :bookings
Room belongs_to :hotel, and habtm :bookings
Booking belongs_to :hotel, and habtm :rooms
i wish to add a condition to the @booking.rooms, they should share the
same
hotel.id as the booking and the collection itself, since a booking is
made
on a single hotel, not many. ¿How can i accomplish that? It should be
something like :conditions => “hotel_id = self.hotel.id” (of course,
this
doesn’t work).
Another thing is that i don’t know if the operator “<<” can be
redefined. If
i redefine Booking.rooms << in some way, i could check if the collection
is
empty, and assign the hotel_id of the room beign added to the collection
to
the booking.hotel.
The third thing/question/approach is that another way is to make Booking
a
“virtual” model, not beign saved directly until payment made, as Cart in
the
Agile dev with rails book.
end
That looks really good! i’ll give it a try, thanks a lot.
Apart from that, is really possible yo redefine the “<<” method/operator
for
a collection?
I’ve seen it used in the associations documentation examples, but there
is
nothing that i have found that actually describes usage. this is not to
say
that it isn’t documented, i just haven’t seen it.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.