So here are the relationships:
class Tutor
has_many :subjects, through: :profile
has_one :profile, dependent: :destroy
end
class Profile
belongs_to :tutor
has_many :subjects, through: :profile_subjects
has_many :profile_subjects
end
class Subject
has_many :profile_subjects
has_many :profiles, through: :profile_subjects
has_many :tutors, through: :profiles
end
# the join model for Profile and Subject
class ProfileSubject
belongs_to :profile
belongs_to :subject
end
Now previously it was all working perfectly fine when I was using the sqlite3 database. But upon deployment to production, I'm getting thrown errors because the database is Postgres.
Here's a simple example of what I do that throws the error
subject = Subject.first
subject.tutors
And the error that is being returned is
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: integer = character varying
As I understand (or was told) it means I'm trying to compare (or join) a varchar to an integer field.
The bigger picture of what I'm actually trying to do is something like Subject.where("name LIKE ?", "#{name}") and be able to find all tutors that have the queried subject. How am I able to access tutors through subject?
(I would just like to note that the associations were working perfectly fine on sqlite3)
subject = Subject.firstfollowed bysubject.tutorsand why is that so? Which are the 2 columns that needs to be integers when i execute that command?schema.rbor take a look at the table definitions within postgres. All foreign keys should have the same datatype as the corresponding primary keys. A good choice is often integer. It's not a general sqlite problem. sqlite is only a little bit more gentle. You column types have to be right.