I'm facing such strange problem. Please take a look within the code

today_date = Time.now.strftime('%Y-%m-%d')

patient_id = session[:patient_id]

query = QueryContainedModel.find(:first, :conditions => ["query_type = ?", 'appointment_reminder'])

This above query creates query_value in below form ie query_value

query_value = "SELECT PATIENT.NAME AS 'first_name' FROM PATIENT, REMINDER WHERE PATIENT.ID = '#{session[:patient_id]}' 
AND REMINDER.PATIENT_ID = '#{session[:patient_id]}' AND REMINDER.DATE >= '#{today_date}'"

However I am not able to fetch values in below code

@value = ModelName.find_by_sql "#{query_value}"
@value.each do |value|
  puts value.

Assist me Thanks

Assuming query = QueryContainedModel.find(:first, :conditions => ["query_type = ?", 'appointment_reminder']) works, the reason for switching to SQL within the next little bit of code? It is simple to still build off query itself - I am presuming your query works within this situation.

You issue is,

You are attempting to gain access to a session value in the model, But periods aren't visible to models, only to sights, assistants and remotes

try passing patient_id like a parameter


inside your controller

query = QueryContainedModel.find(:first, :conditions => ["query_type = ? and patient_id = ?", 'appointment_reminder', session[:patient_id]]