Permalink
Browse files

Merge pull request #3 from pmukerji/master

Updated README to markdown for readability on Github
  • Loading branch information...
2 parents 8fe2c02 + 1e970be commit 7e0555dbdc6540dfa5c2eeedca578db88bd6e0b6 @jackdempsey committed Mar 4, 2013
Showing with 15 additions and 9 deletions.
  1. +15 −9 README → README.md
View
@@ -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 7e0555d

Please sign in to comment.