Error loading association with has_one :through association

I’m getting an error when attempting to view VoterRecord which has a has_on through association with users.

class VoterRecord < ApplicationRecord
  has_one :verification, dependent: :destroy_async
  has_one :user, through: :verification
class Verification < ApplicationRecord
  attr_accessor :verification_pin

  belongs_to :user
  belongs_to :voter_record
class User < ApplicationRecord
  include WorkflowActiverecord

  has_one :verification, dependent: :destroy_async
  accepts_nested_attributes_for :verification

  has_one :voter_record, through: :verification

Expected behavior

Should load a list of VoterRecords

Actual behavior

It failed to load. And I get the error “Your server encountered an error”

Failure Logs

[2021-02-24 09:42:38] Forest 🌳🌳🌳  Records Index error: PG::UndefinedColumn: ERROR:  column users.voter_record_id does not exist
LINE 1: ...7 FROM "voter_records" LEFT OUTER JOIN "users" ON "users"."v...
                                                             ^
HINT:  Perhaps you meant to reference the column "users.voter_records_id".

Context

Please provide any relevant information about your setup.

  • Package Version: 5.4.4
  • Database Dialect: Postgres
  • Database Version: 11
  • Project Name: WeVote

Hi @antarr ,

Welcome to the ForestAdmin community!

Could you please share with me the full log of the SQL request sent to the database? This would help me target what is causing this issue?

Thank you

(887.3ms)  SELECT COUNT(*) FROM "voter_records"
Completed 200 OK in 3008ms (Views: 0.2ms | ActiveRecord: 887.3ms | Allocations: 925806)


Started GET "/forest/VoterRecord?fields%5BVoterRecord%5D=first_name%2Clast_name%2Cmiddle_name%2Cdob%2Cstatus%2Cstate%2Ccreated_at%2Cupdated_at%2Cemail%2Cprecinct%2Cid%2Caddress%2Cverification%2Cuser&fields%5Baddress%5D=id&fields%5Bprecinct%5D=id&fields%5Bstate%5D=name&fields%5Buser%5D=name&fields%5Bverification%5D=id&page%5Bnumber%5D=1&page%5Bsize%5D=15&searchExtended=0&sort=-id&timezone=America%2FChicago" for ::1 at 2021-02-24 09:42:38 -0600
Processing by ForestLiana::UserSpace::VoterRecordController#index as JSON
  Parameters: {"fields"=>{"VoterRecord"=>"first_name,last_name,middle_name,dob,status,state,created_at,updated_at,email,precinct,id,address,verification,user", "address"=>"id", "precinct"=>"id", "state"=>"name", "user"=>"name", "verification"=>"id"}, "page"=>{"number"=>"1", "size"=>"15"}, "searchExtended"=>"0", "sort"=>"-id", "timezone"=>"America/Chicago", "collection"=>"VoterRecord"}
  SQL (1.3ms)  SELECT "voter_records"."first_name" AS t0_r0, "voter_records"."last_name" AS t0_r1, "voter_records"."middle_name" AS t0_r2, "voter_records"."dob" AS t0_r3, "voter_records"."status" AS t0_r4, "voter_records"."state_id" AS t0_r5, "voter_records"."created_at" AS t0_r6, "voter_records"."updated_at" AS t0_r7, "voter_records"."email" AS t0_r8, "voter_records"."precinct_id" AS t0_r9, "voter_records"."id" AS t0_r10, "voter_records"."address_fields" AS t0_r11, "users"."id" AS t1_r0, "users"."email" AS t1_r1, "users"."encrypted_password" AS t1_r2, "users"."reset_password_token" AS t1_r3, "users"."reset_password_sent_at" AS t1_r4, "users"."remember_created_at" AS t1_r5, "users"."sign_in_count" AS t1_r6, "users"."current_sign_in_at" AS t1_r7, "users"."last_sign_in_at" AS t1_r8, "users"."current_sign_in_ip" AS t1_r9, "users"."last_sign_in_ip" AS t1_r10, "users"."confirmation_token" AS t1_r11, "users"."confirmed_at" AS t1_r12, "users"."confirmation_sent_at" AS t1_r13, "users"."unconfirmed_email" AS t1_r14, "users"."first_name" AS t1_r15, "users"."middle_name" AS t1_r16, "users"."last_name" AS t1_r17, "users"."suffix" AS t1_r18, "users"."address_line_1" AS t1_r19, "users"."address_line_2" AS t1_r20, "users"."zip" AS t1_r21, "users"."city" AS t1_r22, "users"."created_at" AS t1_r23, "users"."updated_at" AS t1_r24, "users"."verification_pin" AS t1_r25, "users"."verification_pin_expires_at" AS t1_r26, "users"."address" AS t1_r27, "users"."phone_number" AS t1_r28, "users"."role" AS t1_r29, "users"."state_id" AS t1_r30, "users"."rep" AS t1_r31, "users"."provider" AS t1_r32, "users"."uid" AS t1_r33, "users"."name" AS t1_r34, "users"."image" AS t1_r35, "users"."votes_count" AS t1_r36, "users"."comments_count" AS t1_r37, "users"."issue_issuables_count" AS t1_r38, "users"."status" AS t1_r39, "users"."voter_records_id" AS t1_r40, "verifications"."id" AS t2_r0, "verifications"."user_id" AS t2_r1, "verifications"."status" AS t2_r2, "verifications"."created_at" AS t2_r3, "verifications"."updated_at" AS t2_r4, "verifications"."state_id" AS t2_r5, "verifications"."phone_number" AS t2_r6, "verifications"."address" AS t2_r7, "verifications"."city" AS t2_r8, "verifications"."zip" AS t2_r9, "verifications"."voter_record_id" AS t2_r10, "addresses"."id" AS t3_r0, "addresses"."address_line_1" AS t3_r1, "addresses"."address_line_2" AS t3_r2, "addresses"."city" AS t3_r3, "addresses"."state_id" AS t3_r4, "addresses"."zip" AS t3_r5, "addresses"."zip_plus_4" AS t3_r6, "addresses"."created_at" AS t3_r7, "addresses"."updated_at" AS t3_r8, "addresses"."tsv" AS t3_r9, "addresses"."address_fields" AS t3_r10, "legiscan_model_states"."id" AS t4_r0, "legiscan_model_states"."abbr" AS t4_r1, "legiscan_model_states"."name" AS t4_r2, "legiscan_model_states"."created_at" AS t4_r3, "legiscan_model_states"."updated_at" AS t4_r4, "legiscan_model_states"."slug" AS t4_r5, "legiscan_model_states"."legiscan_data" AS t4_r6, "legiscan_model_states"."legiscan_data_updated_at" AS t4_r7, "legiscan_model_states"."registerable" AS t4_r8, "legiscan_model_states"."header_mappings" AS t4_r9, "precincts"."id" AS t5_r0, "precincts"."identifier" AS t5_r1, "precincts"."number" AS t5_r2, "precincts"."created_at" AS t5_r3, "precincts"."updated_at" AS t5_r4, "precincts"."districts" AS t5_r5, "precincts"."legiscan_model_state_id" AS t5_r6, "precincts"."voter_records_count" AS t5_r7 FROM "voter_records" LEFT OUTER JOIN "users" ON "users"."voter_record_id" = "voter_records"."id" LEFT OUTER JOIN "verifications" ON "verifications"."voter_record_id" = "voter_records"."id" LEFT OUTER JOIN "addresses" ON "addresses"."id" = "voter_records"."address_fields" LEFT OUTER JOIN "legiscan_model_states" ON "legiscan_model_states"."id" = "voter_records"."state_id" LEFT OUTER JOIN "precincts" ON "precincts"."id" = "voter_records"."precinct_id" ORDER BY "voter_records"."id" DESC LIMIT $1 OFFSET $2  [["LIMIT", 15], ["OFFSET", 0]]
[2021-02-24 09:42:38] Forest 🌳🌳🌳  Records Index error: PG::UndefinedColumn: ERROR:  column users.voter_record_id does not exist
LINE 1: ...7 FROM "voter_records" LEFT OUTER JOIN "users" ON "users"."v...
                                                             ^
HINT:  Perhaps you meant to reference the column "users.voter_records_id".

/Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:678:in `exec_params'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:678:in `block (2 levels) in exec_no_cache'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:677:in `block in exec_no_cache'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:697:in `block (2 levels) in log'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block in log'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:688:in `log'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:676:in `exec_no_cache'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `execute_and_clear'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:53:in `exec_query'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:532:in `select'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:69:in `select_all'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:101:in `block in select_all'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:118:in `block in cache_sql'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:109:in `cache_sql'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:101:in `select_all'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:845:in `block (2 levels) in exec_queries'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation/finder_methods.rb:421:in `apply_join_dependency'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:840:in `block in exec_queries'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:868:in `skip_query_cache_if_necessary'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:835:in `exec_queries'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:638:in `load'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:249:in `records'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/relation.rb:244:in `to_ary'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/forest_liana-5.4.4/app/services/forest_liana/resources_getter.rb:82:in `records'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/forest_liana-5.4.4/app/controllers/forest_liana/resources_controller.rb:224:in `render_jsonapi'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/forest_liana-5.4.4/app/controllers/forest_liana/resources_controller.rb:36:in `block (2 levels) in index'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/mime_responds.rb:214:in `respond_to'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/forest_liana-5.4.4/app/controllers/forest_liana/resources_controller.rb:35:in `index'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/abstract_controller/base.rb:228:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actiontext-6.1.1/lib/action_text/rendering.rb:20:in `with_renderer'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actiontext-6.1.1/lib/action_text/engine.rb:55:in `block (4 levels) in <class:Engine>'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:126:in `instance_exec'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:137:in `run_callbacks'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/rescue.rb:22:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/notifications.rb:203:in `block in instrument'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/notifications.rb:203:in `instrument'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/instrumentation.rb:33:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/searchkick-4.4.2/lib/searchkick/logging.rb:212:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/abstract_controller/base.rb:165:in `process'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionview-6.1.1/lib/action_view/rendering.rb:39:in `process'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal.rb:190:in `dispatch'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_controller/metal.rb:238:in `block in action'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/forest_liana-5.4.4/app/controllers/forest_liana/router.rb:40:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/mapper.rb:20:in `block in <class:Constraints>'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/mapper.rb:49:in `serve'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/journey/router.rb:50:in `block in serve'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/journey/router.rb:32:in `each'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/journey/router.rb:32:in `serve'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/route_set.rb:842:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/engine.rb:539:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/railtie.rb:207:in `public_send'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/railtie.rb:207:in `method_missing'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/mapper.rb:20:in `block in <class:Constraints>'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/mapper.rb:49:in `serve'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/journey/router.rb:50:in `block in serve'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/journey/router.rb:32:in `each'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/journey/router.rb:32:in `serve'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/route_set.rb:842:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/twilio-ruby-5.45.1/lib/rack/twilio_webhook_authentication.rb:30:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/http/permissions_policy.rb:22:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/cookies.rb:689:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activerecord-6.1.1/lib/active_record/migration.rb:601:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:132:in `call_app'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:28:in `block in call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:17:in `catch'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:17:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/rack/logger.rb:37:in `call_app'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/rack/logger.rb:26:in `block in call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/tagged_logging.rb:99:in `block in tagged'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/tagged_logging.rb:37:in `tagged'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/tagged_logging.rb:99:in `tagged'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/rack/logger.rb:26:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/quiet_assets.rb:13:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/request_store-1.5.0/lib/request_store/middleware.rb:19:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/request_id.rb:26:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/static.rb:24:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/honeybadger-4.7.3/lib/honeybadger/rack/error_notifier.rb:33:in `block in call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/honeybadger-4.7.3/lib/honeybadger/agent.rb:403:in `with_rack_env'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/honeybadger-4.7.3/lib/honeybadger/rack/error_notifier.rb:30:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/honeybadger-4.7.3/lib/honeybadger/rack/user_feedback.rb:31:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/honeybadger-4.7.3/lib/honeybadger/rack/user_informer.rb:21:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/engine.rb:539:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/puma-5.1.1/lib/puma/configuration.rb:246:in `call'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/puma-5.1.1/lib/puma/request.rb:76:in `block in handle_request'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/puma-5.1.1/lib/puma/thread_pool.rb:337:in `with_force_shutdown'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/puma-5.1.1/lib/puma/request.rb:75:in `handle_request'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/puma-5.1.1/lib/puma/server.rb:431:in `process_client'
        /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/puma-5.1.1/lib/puma/thread_pool.rb:145:in `block in spawn_thread'
Completed 500 Internal Server Error in 14ms (ActiveRecord: 1.3ms | Allocations: 3866)


Started GET "/forest/VoterRecord/count?fields%5BVoterRecord%5D=first_name%2Clast_name%2Cmiddle_name%2Cdob%2Cstatus%2Cstate%2Ccreated_at%2Cupdated_at%2Cemail%2Cprecinct%2Cid%2Caddress%2Cverification%2Cuser&fields%5Bstate%5D=name&fields%5Bprecinct%5D=id&fields%5Baddress%5D=id&fields%5Bverification%5D=id&fields%5Buser%5D=name&searchExtended=0&timezone=America%2FChicago" for ::1 at 2021-02-24 09:42:38 -0600
Processing by ForestLiana::UserSpace::VoterRecordController#count as HTML
  Parameters: {"fields"=>{"VoterRecord"=>"first_name,last_name,middle_name,dob,status,state,created_at,updated_at,email,precinct,id,address,verification,user", "state"=>"name", "precinct"=>"id", "address"=>"id", "verification"=>"id", "user"=>"name"}, "searchExtended"=>"0", "timezone"=>"America/Chicago", "collection"=>"VoterRecord"}
   (194.5ms)  SELECT COUNT(*) FROM "voter_records"
Completed 200 OK in 198ms (Views: 0.1ms | ActiveRecord: 194.5ms | Allocations: 30408)

Hello @antarr !

I just had a look on your error. Obviously the first question that comes to my mind is : does the column voter_record_id exist in your users table ?

Apparently there might have been a small mistake with the name of the column as it’s guessing that the correct name could be voter_records_id (the “s”).

There is no voter_record_id in users table. The relationship is a has_one through. The verifications has a user_id and voter_record_id to maps a User to a Verification

# == Schema Information
#
# Table name: verifications
#
#  id              :integer          not null, primary key
#  phone_number    :string
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  user_id         :integer
#  voter_record_id :bigint

I’m not sure about your model definition, you’re specifying in your User model that verification is a junction table, while also specifying that it’s a has_one.

Also, who belongs to who ? In your case you say that

User hasOne VoterRecord
VoterRecord hasOne User

I don’t know the context, but I think I would go for

User hasOne VoterRecord
VoterRecord belongsTo User

So :

class VoterRecord < ApplicationRecord
  belongs_to :user, through: :verification

class Verification < ApplicationRecord
  attr_accessor :verification_pin
  belongs_to :user
  belongs_to :voter_record

class User < ApplicationRecord
  include WorkflowActiverecord
  accepts_nested_attributes_for :verification
  has_one :voter_record, through: :verification

I’m not that much skilled with Ruby so I might be wrong, tell me if it helps.