Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
Rails incluye error: UndefinedTable: ERROR: falta la entrada de la cláusula FROM para la tabla

Prefiero usar include para conectar mis tres tablas. Tengo tres modelos que necesito conectar, como Registro, Estudiante y Horario. Aquí está mi modelo de Asociación

 class Student < ApplicationRecord belongs_to :register end class Register < ApplicationRecord has_one :student belongs_to :schedule end class Schedule < ApplicationRecord belongs_to :course belongs_to :teacher has_many :days, :dependent => :destroy, :class_name => 'ScheduleDay' has_many :registers end

Aquí está mi controlador

 def index @students = Student.includes([register: :schedule]) @students = @students.order 'students.created_at DESC' if params[:status_id] && params[:status_id].to_i > 0 @students = @students.where 'students.status_id = ?', params[:status_id] end if params[:id] && params[:id].to_i > 0 @students = @students.where 'cast(students.id as varchar) like (?)', "%#{params[:id]}%" end if params[:full_name] && params[:full_name].to_s.length > 0 @students = @students.where 'lower(registers.name_in_indonesian || registers.name_in_chinese) like lower(?)', "%#{params[:full_name]}%" end if params[:course_id] && params[:course_id].to_i > 0 @students = @students.where 'schedules.course_id = ?', params[:course_id] end @students = @students.paginate(page: params[:page], per_page: 30) end

Recibí el siguiente error:

 PG::UndefinedTable: ERROR: missing FROM-clause entry for table "schedules" LINE 1: SELECT "students".* FROM "students" WHERE (schedules.course_...

Traté de depurar usando la consola Rails pero terminé con (Object no admite #inspect) ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Debe unirse a esas tablas si desea consultarlas, includes no es suficiente:

 @students = Student.joins(register: :schedule)

o agregue una llamada de references :

 @students = Student.includes(register: :schedule).references(register: :schedule)

includes reducirá el número de consultas de la base de datos para acceder a las tablas incluidas, pero no se UNirá a las tablas.

over 4 years ago · Santiago Trujillo Report

0

Creo que estás teniendo algunas migraciones no migradas. Por favor, corre

rastrillar db: migrar

Después de ejecutar el comando anterior, reinicie la consola Rails y luego intente lo mismo. No obtendrá este error.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!