Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

0

If you want to include foreign key , write

belongs_to: PreferredDayTime

In your DateTime model class

over 4 years ago · Santiago Trujillo Relatório

0

You can specify foreign key:

has_many :days, class_name: "Days", foreign_key: "any_desirable_key_id"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda