Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
Specify table for Rails Model

I'm running into an issue with a foreign key constraint.

I have three models:

PreferredDayTime (join table between users and)

DayTime (a collection of daytimes - connecting a day of the week and time of day)

and Day (each day of the week).

When creating a PreferredDayTime, I get a foreign key constraint, that the specified day_time_id does not exist on the table days.

I think rails is looking for a time_id in the days table, instead of a day_time_id in the day_times table.

How can I specify that the foreign key is not on the days table?

Not sure what to google with respect to the overlapping names

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

If you want to include foreign key , write

belongs_to: PreferredDayTime

In your DateTime model class

over 4 years ago · Santiago Trujillo Denunciar

0

You can specify foreign key:

has_many :days, class_name: "Days", foreign_key: "any_desirable_key_id"
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda