Answer the question
In order to leave comments, you need to log in
PG::UndefinedColumn?
I have a relationship between tables like this.
And I need to display data from the masters table for the report. And at the moment, my request refers to the wrong id, i.e. it's looking for a column masters.team_id
as well masters.teams_id
. Here is the complete error:
PG::UndefinedColumn: ERROR: column masters.team_id does not exist LINE 1: SELECT "masters"."full_name" FROM "masters" WHERE "masters".... ^ HINT: Reference to column "masters.teams_id" may have been intended . : SELECT "masters"."full_name" FROM "masters" WHERE "masters"."team_id" = $1
class Report < ActiveRecord::Base
self.table_name = 'reports'
self.primary_key = :report_id
belongs_to :team, foreign_key: 'teams_id'
def get_team_name
"#{team.full_name}"
end
def get_masters_name
"#{team.masters.pluck(:full_name)}"
end
end
class Team < ActiveRecord::Base
self.table_name = 'teams'
self.primary_key = :team_id
has_many :reports
has_many :masters
end
class Master < ActiveRecord::Base
self.table_name = 'masters'
self.primary_key = :master_id
belongs_to :team, foreign_key: 'teams_id'
end
def get_masters_name
"#{team.masters.pluck(:full_name)}"
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question