I have a bookroom model
class BookRoom < ApplicationRecord
has_many :room_customers
has_many :rooms, :through => :room_customers
after_update :add_dynamic_change, :on => :show
private
def add_dynamic_change
room = Room.find self.room
room.update_column :availability, true
end
end
(0.1ms) begin transaction
CACHE (0.0ms) SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = ? LIMIT ? [["id", 17], ["LIMIT", 1]]
-> SQL (1.2ms) UPDATE "rooms" SET "availability" = 't' WHERE "rooms"."id" = ? [["id", 17]]
SQL (0.3ms) INSERT INTO "room_customers" ("created_at", "updated_at", "book_room_id", "room_id") VALUES (?, ?, ?, ?) [["created_at", 2016-08-19 13:40:11 UTC], ["updated_at", 2016-08-19 13:40:11 UTC], ["book_room_id", 219], ["room_id", 17]]
(2.0ms) commit transaction
From: /Users/chineduabalogu/work/hotel-management/app/controllers/book_rooms_controller.rb @ line 20 BookRoomsController#create:
13: def create
14: @customer = Customer.find(params[:customer_id])
15: @customer_room = @customer.book_rooms.create(book_rooms_params)
16: @room = Room.find @customer_room.room
17: require 'pry'; binding.pry
18: @book_rooms = BookRoom.where room_number: @room.room_number
-> 19: @room.book_rooms << @customer_room
=> 20: require 'pry'; binding.pry
21: flash[:notice] = "Customer has been added to room"
22: redirect_to customer_path(@customer)
23: end
Are there any collection methods that dont update the database? because "<<" this one does an update I dont need. I tried @room.book_rooms.build @customer_room.attributes but I dont know how i can save it