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

  • Home
  • SEARCH
  • 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 7917445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:08:57+00:00 2026-06-03T15:08:57+00:00

Suppose we have three models PATIENTS, NURSES, and their association model APPOINTMENTS. This week

  • 0

Suppose we have three models PATIENTS, NURSES, and their association model APPOINTMENTS.

This week all patients have to meet with their nurses.

A patient has many nurses, and a nurse has many patients. Likewise, a patient has many appointments, but only one per nurse, and a nurse has many appointments, but only one per patient.

class Patient < ActiveRecord::Base 
  has_many :appointments
  has_many :nurses, :through => :appointments
end


class Nurse < ActiveRecord::Base 
  has_many :appointments
  has_many :patients, :through => :appointments
end


class Appointment < ActiveRecord::Base
  belongs_to :patient
  belongs_to :nurse
end

Obviously, the APPOINTMENT belongs to both the patient and the nurse.

However, I also want a way for the nurse to be able to tick off whether or not the patient showed up. I implemented this within the migration like such:

class CreateAppointments < ActiveRecord::Migration
  def self.up
    create_table :appointments do |t|
      t.references :patient
      t.references :nurse
      t.boolean "present", :default => false
      t.timestamps
    end
    add_index :job_enrollments, ['patient_id', 'nurse_id']
  end

  def self.down
    drop_table :appointments
  end

end

In the console, I could create an instance of everything, and could do the following:

appt = Appointment.new
patient = Patient.new
nurse = Nurse.new

patient.appointments << appt
nurse.appointments << appt

Now, here comes the question: How do I implement it so that the Nurse in that appointment is able to edit the value of the boolean to TRUE? So far, I can change the value of the instance of the appointment by typing:

appt.present = true

But this not what I want. I want the nurse to be able to modify this association, and lock out the patient from changing anything.

Should I simply not be using rich associations for this?

  • 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-03T15:09:00+00:00Added an answer on June 3, 2026 at 3:09 pm

    I’m assuming your question is about how to use these associations. You can recall and modify the appointment record after the appointment is kept, like so:

    # current_nurse is the nurse using the system and reporting
    appt = current_nurse.appointments.where(:patient_id => params[:patient_id]).first
    appt.update_attribute :present, true
    

    To prevent the patient from accessing and modifying the appointment, you would need an authentication mechanism, such as devise. Then only grant Nurses permission to access the system.

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

Sidebar

Related Questions

Suppose I have something like this in my models.py: class Hipster(models.Model): name = CharField(max_length=50)
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have a string like this: one two three four five six seven
Suppose I have three models: Student , SchoolClass , and DayOfWeek . There is
Let's suppose we have these three models: - cagegory ( id, name ) -
Suppose I have a Book model, which contains many Page models. The routing for
Suppose I have this model: public class ViewModel { [Required] public string UserInput {
Suppose I have a Django model as follows: class Person(models.Model): first_name = models.CharField(max_length=50) last_name
Suppose you have two models, User and City, joined by a third model CityPermission:
suppose we have three tables in the Database: tbl_companymaster(company_id(PK),company_name) tbl_papermaster(paper_id(PK),paper_name,rate) tbl_rate(rate_id(PK),company_id(FK ),paper_id(FK),rate) we have

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.