Rails Admin generating the wrong SQL query

295 Views Asked by At

So I have a Service model that has many Comment using the acts_as_commentable_with_threading gem.

class Service < ActiveRecord::Base
  has_many :comments, dependent: :destroy
end

class Comment < ActiveRecord::Base
  # Boilerplate gem generated code
end

Here's the schema the gem generates:

create_table "comments", force: true do |t|
    t.integer  "commentable_id",          default: 0
    t.string   "commentable_type"
    t.string   "title"
    t.text     "body"
    t.string   "subject"
    t.integer  "user_id",                 default: 0,   null: false
    t.integer  "parent_id"
    t.integer  "lft"
    t.integer  "rgt"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "cached_votes_total",      default: 0
    t.integer  "cached_votes_score",      default: 0
    t.integer  "cached_votes_up",         default: 0
    t.integer  "cached_votes_down",       default: 0
    t.integer  "cached_weighted_score",   default: 0
    t.integer  "cached_weighted_total",   default: 0
    t.float    "cached_weighted_average", default: 0.0
  end

Rails admin is generating the wrong query when I try to access a Service. It sees the has_many :comments and jumps to it.

http://localhost:5000/admin/service/999

PG::UndefinedColumn: ERROR: column comments.service_id does not exist LINE 1: SELECT "comments".* FROM "comments" WHERE "comments"."servi...


How can I fix this error?

0

There are 0 best solutions below