2013-06-04 2 views
0

User has_many :organizations는 참조 _id 객체가 아닌 객체가 직접

create_table "organizations", :force => true do |t| 
    t.string "name" 
    t.integer "founder_id" 

내가 founder_id를 할당하지만, 설립자 (방법 누락)에 액세스 할 수 없습니다 액세스 할 수 있습니다.

class CreateOrganizations < ActiveRecord::Migration 
def change 
create_table :organizations do |t| 
    t.string :name 
    t.belongs_to :founder, :class_name => "User" 

내가 내가 Oranization에 설립자 (사용자) ATTR에 액세스 할 수 있도록 변경해야합니까?

답변

1

방법 belongs_to이 같은 조직 클래스에서 호출해야합니다

class Organization 
    belongs_to :founder, :class_name => 'User' 
end 

및 마이그레이션에

:

create_table :organizations do |t| 
    t.string :name 
    t.integer :founder_id 
end 
+0

아, 그래서 그 뒤로이 .. 시도했다. – quantumpotato

+0

이전을 마치고 클래스를 업데이트했습니다. 고마워! – quantumpotato

+0

흠 .. 지금이 문제는 rails_admin과 같습니다 : http://stackoverflow.com/questions/16929802/no-such-column-with-a – quantumpotato

관련 문제