Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

migration examples, finally!

  • Loading branch information...
commit e4a2cc75961ffc32190e9a774968d3b182e3e59c 1 parent 0d04e56
@evan authored
Showing with 30 additions and 3 deletions.
  1. +30 −0 README
  2. +0 −3  TODO
View
30 README
@@ -63,6 +63,21 @@ One of the child models:
# nothing
end
+For your parent and child models, you don't need any special fields in your migration. For the join model (GuestsKennel), use a migration like so:
+
+ class CreateGuestsKennels < ActiveRecord::Migration
+ def self.up
+ create_table :guests_kennels do |t|
+ t.references :guest, :polymorphic => true
+ t.references :kennel
+ end
+ end
+
+ def self.down
+ drop_table :guests_kennels
+ end
+ end
+
See ActiveRecord::Associations::PolymorphicClassMethods for more configuration options.
== Helper methods example
@@ -113,6 +128,21 @@ Now, dogs and cats can eat birds and cats. Birds can't eat anything (they aren't
In this case, each guest/eaten relationship is called a Devouring.
+In your migration, you need to declare both sides as polymorphic:
+
+ class CreateDevourings < ActiveRecord::Migration
+ def self.up
+ create_table :devourings do |t|
+ t.references :guest, :polymorphic => true
+ t.references :eaten, :polymorphic => true
+ end
+ end
+
+ def self.down
+ drop_table :devourings
+ end
+ end
+
See ActiveRecord::Associations::PolymorphicClassMethods for more.
== Tagging generator
View
3  TODO
@@ -1,5 +1,2 @@
-* Does :namespace key definitely work with doubles?
-* Migration examples in docs
-* Controller for tagging generator
* Tag cloud method
Please sign in to comment.
Something went wrong with that request. Please try again.