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

186
Views
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 answers
Answer question

0

If you want to include foreign key , write

belongs_to: PreferredDayTime

In your DateTime model class

over 4 years ago · Santiago Trujillo Report

0

You can specify foreign key:

has_many :days, class_name: "Days", foreign_key: "any_desirable_key_id"
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!