jquery - Opinion about migrate and use 2 tables on Rails 4 -
i trying build reservation system. until now, did reservation table , check availability using model:
class reservations < activerecord::base # user_id # room_id # start_date # end_date # day (integer) # iscanceled (false automatically) belongs_to :user, :class_name => "users", :foreign_key => "user_id" belongs_to :room, :class_name => "rooms", :foreign_key => "room_id" end
now want add "music lessons" table fetch , add courses repeats every day. model:
class roomschedule < activerecord::base # name # start_date # end_date # room_id # day (integer) belongs_to :room, :class_name => "rooms", :foreign_key => "room_id" end
in reservations controller, display programs using sql query:
@all = reservations.where("start_date > ?", time.now.beginning_of_day).order("start_date asc")
but want merge reservations table roomschedule table check , display current ongoing courses.
do have suggestions?
thanks
sounds want inner join:
@current_courses = reservations.joins(:roomschedule).where("end_date < time.now && start_date > time.now").order("start_date asc")
updated:
day_index = date.today.strftime("%u") # or %w depending on index @todays_courses = reservations.joins(:roomschedule).where(day: day_index).order("start_date asc")
Comments
Post a Comment