I got this error: uninitialized constant User::shift
here's the stack trace
created_shifts = current_user.shifts.in_state(:created).first
Class < User
self.primary_key = 'guid'
has_many :shifts, foreign_key: 'user_guid', primary_key: 'guid', class_name: 'shift'
Class < Shift
belongs_to :user, foreign_key: 'user_guid', primary_key: 'guid', class_name: 'user'
Thanks for the help!
At a glance, try removing
class_name from both of your associations. There's no need to do that (as far as I'm aware) unless the class name is different than the name you want to use when calling the association.
the class name is not different, I added that hoping that will fix the problem but it did not.
Look at your foreign/primary key assignments on your Shift model, that should be:
belongs_to :user, foreign_key: 'guid', primary_key: 'user_guid'
After you adjust the foreign/primary key names if it still doesn't work, double check your model file names and their class declarations to ensure there's no typos.
Another thing I just noticed, are your models inheriting from
ApplicationRecord? Your code doesn't show that to be the case. They should be:
class Shift < ApplicationRecord ... end
class User < ApplicationRecord ... end
Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.