title: ActiveModel::MissingAttributeError: missing attribute: project_id when calling to_json
body: <p>I wrote a below query class, which is throwing a missing attribute error which I didn't put in the select method anywhere. Any idea from where this error might be coming? Why <code>project_id</code> is being searched in the <code>to_json</code> method.</p>
  <pre><code>class WorkitemPriceResearchPresenter
    def initialize(company)
      @company = company
    end
  
    def query
      @workitems ||= \
        @company
          .workitems
          .joins(
            :workitem_category,
            :workitem_status,
            { project: [:shipyard, {vessel: :vessel_category}] }, 
          )
          .select &lt;&lt;-EOS
            workitems.id as id,
            projects.sequential_id as sequential_id,
            vessels.name as vessel_name,
            vessel_categories.code as vessel_category,
            shipyards.name as shipyard,
            workitems.item_code as item_code,
            workitems.description as description,
            workitems.unit as unit,
            workitems.price_cents as price_cents,
            workitems.currency as currency,
            workitems.quantity as quantity,
            workitem_statuses.name as status,
            workitems.discount as discount,
            DATE_PART('year', projects.scheduled_from::date) as scheduled_from_year,
            projects.scheduled_from as scheduled_from,
            DATE_PART('year', projects.scheduled_to::date) as scheduled_to_year,
            projects.scheduled_to as scheduled_to,
            workitem_categories.name as Category
          EOS
    end
  
    def as_json
      query.to_json
    end
  end
  </code></pre>
  <p>Error is:</p>
  <pre><code>pry(main)&gt; WorkitemPriceResearchPresenter.new(company).query.as_json
    Workitem Load (33.7ms)  SELECT           workitems.id as id,
            projects.sequential_id as sequential_id,
            vessels.name as vessel_name,
            vessel_categories.code as vessel_category,
            shipyards.name as shipyard,
            workitems.item_code as item_code,
            workitems.description as description,
            workitems.unit as unit,
            workitems.price_cents as price_cents,
            workitems.currency as currency,
            workitems.quantity as quantity,
            workitem_statuses.name as status,
            workitems.discount as discount,
            DATE_PART('year', projects.scheduled_from::date) as scheduled_from_year,
            projects.scheduled_from as scheduled_from,
            DATE_PART('year', projects.scheduled_to::date) as scheduled_to_year,
            projects.scheduled_to as scheduled_to,
            workitem_categories.name as Category
   FROM &quot;workitems&quot; INNER JOIN &quot;workitem_categories&quot; ON &quot;workitem_categories&quot;.&quot;id&quot; = &quot;workitems&quot;.&quot;workitem_category_id&quot; INNER JOIN &quot;workitem_statuses&quot; ON &quot;workitem_statuses&quot;.&quot;id&quot; = &quot;workitems&quot;.&quot;workitem_status_id&quot; INNER JOIN &quot;projects&quot; ON &quot;projects&quot;.&quot;id&quot; = &quot;workitems&quot;.&quot;project_id&quot; AND &quot;projects&quot;.&quot;deleted_at&quot; IS NULL INNER JOIN &quot;shipyards&quot; ON &quot;shipyards&quot;.&quot;id&quot; = &quot;projects&quot;.&quot;shipyard_id&quot; AND &quot;shipyards&quot;.&quot;deleted_at&quot; IS NULL INNER JOIN &quot;vessels&quot; ON &quot;vessels&quot;.&quot;id&quot; = &quot;projects&quot;.&quot;vessel_id&quot; AND &quot;vessels&quot;.&quot;deleted_at&quot; IS NULL INNER JOIN &quot;vessel_categories&quot; ON &quot;vessel_categories&quot;.&quot;id&quot; = &quot;vessels&quot;.&quot;vessel_category_id&quot; AND &quot;vessel_categories&quot;.&quot;deleted_at&quot; IS NULL WHERE &quot;workitems&quot;.&quot;deleted_at&quot; IS NULL AND &quot;workitems&quot;.&quot;company_id&quot; = $1  [[&quot;company_id&quot;, &quot;c61e4368-1a60-464b-8002-9da31bf301e5&quot;]]
  ActiveModel::MissingAttributeError: missing attribute: project_id
  from /Users/ar/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activerecord-4.2.11.3/lib/active_record/attribute_methods/read.rb:93:in `block in _read_attribute'
  </code></pre>
  <p>Let me know if I need to provide any more information.</p>