P
P
Pix32019-01-29 09:07:12
Ruby on Rails
Pix3, 2019-01-29 09:07:12

PG::UndefinedColumn?

I have a relationship between tables like this. 5c4fec274f690499180346.png
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_idas 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

report.rb:
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

team.rb:
class Team < ActiveRecord::Base
  self.table_name = 'teams'
  self.primary_key = :team_id
  has_many :reports  
  has_many :masters
end

master.rb:
class Master < ActiveRecord::Base
  self.table_name = 'masters'
  self.primary_key = :master_id
  belongs_to :team, foreign_key: 'teams_id'
end

An error occurs here:
def get_masters_name
   "#{team.masters.pluck(:full_name)}"
 end

How can this be fixed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question