我試圖建立一個數據庫的URL(鏈接)。我有一個分類模型,它有許多鏈接。混合has_one和has_and_belongs_to_many關聯
這是我跑遷移:
class CreateLinksCategories < ActiveRecord::Migration
def self.up
create_table :links_categories, :id => false do |t|
t.references :link
t.references :category
end
end
def self.down
drop_table :links_categories
end
end
這裏的鏈接模式:
class Link < ActiveRecord::Base
validates :path, :presence => true, :format => { :with => /^(#{URI::regexp(%w(http
https))})$|^$/ }
validates :name, :presence => true
has_one :category
end
這裏的類型模型:
class Category < ActiveRecord::Base
has_and_belongs_to_many :links
end
而這裏的錯誤控制檯踢來踢去,當我試圖在第一鏈路與第一類相關聯:
>>link = Link.first
=> #<Link id: 1, path: "http://www.yahoo.com", created_at: "2011-01-10...
>>category = Category.first
=> #<category id : 1, name: "News Site", created_at: "2011-01-11...
>>link.category << category
=> ActiveRecord::StatementInvalid: SQLite3::Exception: no such column :
categories.link_id:
是我的錯協會還是我失去了在數據庫中的東西嗎?我期望它找到links_categories表。任何幫助表示讚賞。
這工作。謝謝! – Thomas 2011-01-11 18:13:21