{"issue":{"user":{"id":583864,"login":"boynamedbri","url":"https://api.github.com/users/boynamedbri","gravatar_id":"a7b787ce9e0f212e714c5b43d5077714","avatar_url":"https://secure.gravatar.com/avatar/a7b787ce9e0f212e714c5b43d5077714?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"milestone":null,"created_at":"2011-12-22T23:32:31Z","title":"Problem with has_one and :foreign_key","updated_at":"2011-12-22T23:38:34Z","labels":[],"state":"closed","id":2643263,"html_url":"https://github.com/gregbell/active_admin/issues/872","pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"closed_at":"2011-12-22T23:38:34Z","number":872,"body":"I apologize ahead of time if I'm making a silly mistake here. I'm not yet very experienced with Rails.\r\n\r\nI have a migration like this:\r\n\r\n```ruby\r\n  def up\r\n    create_table :questions do |t|\r\n      t.text :text\r\n    end\r\n\r\n    create_table :answers do |t|\r\n      t.integer :question_id\r\n      t.integer :next_question_id\r\n      \r\n      t.string :text\r\n    end\r\n  end\r\n```\r\n\r\nI then have Question and Answer models like this:\r\n\r\n```ruby\r\nclass Question < ActiveRecord::Base\r\n  has_many :answers, :dependent => :destroy\r\nend\r\n\r\nclass Answer < ActiveRecord::Base\r\n  belongs_to :question\r\n  has_one :next_question, :class_name => \"Question\", :foreign_key => 'next_question_id'\r\nend\r\n```\r\n\r\nThese relationships seem to work okay in the console:\r\n\r\n```ruby\r\nirb(main):007:0> q1 = Question.new\r\n=> #<Question id: nil, text: nil>\r\nirb(main):008:0> q1.text = \"Question 1 (Parent)\"\r\n=> \"Question 1 (Parent)\"\r\nirb(main):009:0> q2 = Question.new\r\n=> #<Question id: nil, text: nil>\r\nirb(main):010:0> q2.text = \"Question 2 (Next)\"\r\n=> \"Question 2 (Next)\"\r\nirb(main):011:0> a = Answer.new\r\n=> #<Answer id: nil, question_id: nil, next_question_id: nil, text: nil>\r\nirb(main):012:0> a.question = q1\r\n=> #<Question id: nil, text: \"Question 1 (Parent)\">\r\nirb(main):013:0> a.next_question = q2\r\n=> #<Question id: nil, text: \"Question 2 (Next)\">\r\nirb(main):014:0> a.question\r\n=> #<Question id: nil, text: \"Question 1 (Parent)\">\r\nirb(main):015:0> a.next_question\r\n=> #<Question id: nil, text: \"Question 2 (Next)\">\r\n```\r\n\r\nHowever, when I try to create an Answer in Active Admin I encounter 2 issues. Firstly, the \"new\" page lists the belongs_to Question but not the has_one.\r\n\r\nNext, if I click \"Create Answer\" I see the following SQL error:\r\n\r\n```sql\r\nSQLite3::SQLException: no such column: questions.next_question_id: SELECT  \"questions\".* FROM \"questions\"  WHERE \"questions\".\"next_question_id\" = 1 LIMIT 1\r\n```","url":"https://api.github.com/repos/gregbell/active_admin/issues/872","comments":1,"assignee":null},"action":"closed"}