Get all records that has_one polymorphic recrd

33 Views Asked by At

How can I create a scope that fetches all Jobs that have one Jsoon?

  #Job
  has_one :jsoon, as: :jsoonable, dependent: :destroy


  def self.hasjsoon
    where(joins(:jsoon))
  end


#Console:
Job.hasjsoon

Gives the error

Unsupported argument type: #<Job::ActiveRecord_Relation:0x00007f9e804936c8> (Job::ActiveRecord_Relation))
1

There are 1 best solutions below

0
byakugie On

You don't need where to fetch all Jobs that have one Jsoon

This is enough

  def self.hasjsoon
    joins(:jsoon)
  end