Commit 760f47f2

mo k <mo@mokhan.ca>
2011-08-03 02:24:27
add creation to category join table.
1 parent b0805a9
app/models/category.rb
@@ -1,2 +1,3 @@
 class Category < ActiveRecord::Base
+  has_and_belongs_to_many :creations
 end
app/models/creation.rb
@@ -3,6 +3,7 @@ class Creation < ActiveRecord::Base
   validates :image,  :presence => true
   attr_accessible :user_id, :story, :name, :image, :remote_image_url
   belongs_to :user
+  has_and_belongs_to_many :categories
   mount_uploader :image, ImageUploader
 
   define_index do
db/migrate/20110803021631_create_creation_category_join_table.rb
@@ -0,0 +1,12 @@
+class CreateCreationCategoryJoinTable < ActiveRecord::Migration
+  def self.up
+    create_table :creations_categories, :id => false do |t|
+      t.integer :creation_id
+      t.integer :category_id
+    end
+  end
+
+  def self.down
+    drop_table :creations_categories
+  end
+end
db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20110803020957) do
+ActiveRecord::Schema.define(:version => 20110803021631) do
 
   create_table "authentications", :force => true do |t|
     t.integer  "user_id"
@@ -35,6 +35,11 @@ ActiveRecord::Schema.define(:version => 20110803020957) do
     t.string   "image"
   end
 
+  create_table "creations_categories", :id => false, :force => true do |t|
+    t.integer "creation_id"
+    t.integer "category_id"
+  end
+
   create_table "users", :force => true do |t|
     t.string   "email",                                 :default => "", :null => false
     t.string   "encrypted_password",     :limit => 128, :default => "", :null => false