2013-06-12 5 views
7

내 Ruby On Rails 프로젝트에서 has_and_belongs_to_many 연관성에 문제가 있습니다. 여기 has_and_belongs_to_many assocation does not work

내 모델입니다 :

class Store < ActiveRecord::Base 
    attr_accessible :address, :city, :map_url, :name, :uimage_url 
    has_and_belongs_to_many :furnitures_id 
end 

class Furniture < ActiveRecord::Base 
    attr_accessible :description, :image_url, :maintenance, :name, :size 
    has_and_belongs_to_many :store_id 
end 

이 내 가입 테이블 마이그레이션 :

create_table "furnitures_stores", :id => false, :force => true do |t| 
    t.integer "furniture_id" 
    t.integer "store_id" 
end 

내가 다음 seed.rb와 함께 몇 가지 값을 삽입하려고 :

Furniture.delete_all 
furnitures = Furniture.create([{name: 'aaaa 1'}]) 

Store.delete_all 
storee = Store.create([{name: 'S 1'}]) 

그러나 그것은 작동하지 않는다;

**rake aborted! 
uninitialized constant Store::FurnituresId** 

답변

8

당신은 has_and_belongs_to_many :furnitureshas_and_belongs_to_many :stores 필요 :이 오류가 있습니다. 외래 키가 아닌 모델을 참조해야합니다.

자세한 내용은 A Guide to ActiveRecord Associations을 참조하십시오.

+0

하지만 모델을 어떻게 참조 할 수 있습니까? – Teo

+0

@Teo 무슨 뜻인지 모르겠다. –

+0

지금은 이해 .. 그리고 그것은 작동합니다 .. 감사합니다 Logged – Teo