• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

129
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

about 3 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

about 3 years ago · Santiago Trujillo Denunciar

0

You can specify foreign key:

has_many :days, class_name: "Days", foreign_key: "any_desirable_key_id"
about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda