Skip to content
Browse files

updated readme style for github

  • Loading branch information...
1 parent 8fe2c02 commit 1e970bec4a10b1034f1ba8000df69bfac4bece2c @pmukerji pmukerji committed Mar 4, 2013
Showing with 15 additions and 9 deletions.
  1. +15 −9 README → README.md
View
24 README → README.md
@@ -1,28 +1,31 @@
-Sequel Polymorphic
-==================
+#Sequel Polymorphic
A simple plugin for Sequel::Model's that lets you easily create polymorphic associations.
-ActiveRecord Style
-------------------
+##ActiveRecord Style
+```ruby
class Asset < ActiveRecord::Base
- belongs_to :attachable, :polymorphic => true
+ belongs_to :attachable, :polymorphic => true
end
class Post < ActiveRecord::Base
- has_many :assets, :as => :attachable
+ has_many :assets, :as => :attachable
end
class Note < ActiveRecord::Base
- has_many :assets, :as => :attachable
+ has_many :assets, :as => :attachable
end
@asset.attachable = @post
@asset.attachable = @note
+```
+
+## Sequel (without plugin)
In Sequel you would do the following:
+```ruby
class Asset < Sequel::Model
many_to_one :attachable, :reciprocal=>:assets, \
:dataset=>(proc do
@@ -101,10 +104,13 @@ end
@asset.attachable = @post
@asset.attachable = @note
-
+```
Thats quite a bit of code. With sequel_polymorphic you can now do:
+## Polymorphic
+
+```ruby
class Note < Sequel::Model
is :polymorphic
one_to_many :assets, :as => :attachable
@@ -115,4 +121,4 @@ class Asset < Sequel::Model
many_to_one :attachable, :polymorphic => true
end
-voila!
+```

0 comments on commit 1e970be

Please sign in to comment.
Something went wrong with that request. Please try again.