Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:41:41+00:00 2026-06-17T12:41:41+00:00

I have two models Appointment and Schedule, in Appointment I have a time field

  • 0

I have two models Appointment and Schedule, in Appointment I have a time field called adate and in schedule I have start_time and end end_time fields.

I want to compare the value in adate with the the values within start_time and end_time to see if is possible to make the appointment at that hour.

How can I compare those values?

  create_table "appointments", :force => true do |t|
    t.integer  "doctor_id"
    t.date     "adate"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.time     "atime"
  end

  create_table "schedules", :force => true do |t|
    t.string   "day"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.integer  "doctor_id"
    t.time     "start_time"
    t.time     "end_time"
  end

It should be a validation but should I implement this?

Model

class Appointment < ActiveRecord::Base
  attr_accessible :adate, :atime, :doctor_id  
  validates :adate, :presence => true     
  belongs_to :doctor
  validates_date :adate, :after => lambda { Date.current }  
end

class Schedule < ActiveRecord::Base
  attr_accessible :doctor_id, :day, :end_time, :start_time  
  belongs_to :doctor
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:41:42+00:00Added an answer on June 17, 2026 at 12:41 pm

    From http://guides.rubyonrails.org/active_record_validations_callbacks.html#custom-methods, you can see how to write arbitrary methods for validation.

    In your case, you would probably write something of this form.

    class Appointment < ActiveRecord::Base
        # ... All the other stuff
        validate :appointment_time_is_valid_for_day
    
        def appointment_time_is_valid_for_day
            # TODO: Get the schedule for that day/doctor.
            unless schedule.start_time <= atime and
              atime <= schedule.end_time
                errors.add(:atime, "Doctor's not in at this time")
            end
        end
    end
    

    This assumes that you already have some way to get the schedule of the doctor on the day of the appointment. I don’t know enough about your models to tell you how to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models called Album and Photo . I want the url to
I have two models both with a M2M field pointing to the same third
I have two models, one called Notes and one called Comments. Comments can be
I have two models in Django: groups and entries. Groups has a many-to-many field
I have two models: class Group < ActiveRecord::Base belongs_to :sites end class Site <
I have two models, user and card and i want to establish an association
I have two models: Director, and Film. I want to create a web query
I have two models Group and Person that I want to have a many-to-many
I have two models like this: class CompanyResource(ModelResource): class Meta: queryset = Company.objects.all() fields
I have two Models called User and Membership. User has_many :memberships Membership belongs_to :user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.