Created
November 17, 2010 22:11
-
-
Save chrisyour/704206 to your computer and use it in GitHub Desktop.
My quest to create new Rails 3 Double Sided Polymorphic Gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ok, I'm creating a paired down version of Has_Many_Polymorphs in Rails 3 and making use of Arel. A great way to learn! | |
# Super simple setup: | |
class Content < ActiveRecord::Base | |
polly :parents => :posts, :children => [:images, :paragraphs, :quotes] | |
end | |
class Post < ActiveRecord::Base | |
end | |
class Image < ActiveRecord::Base | |
end | |
class Paragraph < ActiveRecord::Base | |
end | |
class Quote < ActiveRecord::Base | |
end | |
# Post has many :images, :paragraphs, and :quotes and many polymorphic children. | |
p = Post.first # => #<Post> | |
p.children # => Currently returns an array of records returned from a special Arel table to select the polymorphic data | |
p.children.order('contents.order ASC') # => I would like this to append order() to the Arel table, then return the results | |
p.children.where('contents.approved = ?', true).order('contents.order ASC') # => I would like this to append both where() and order() to the Arel table, then return the results | |
# My question is this: | |
# How can I extend the sweetness of ActiveRecord to allow chaining of finder methods to an existing Arel table, then automatically execute the Arel SQL rather than returning an Arel table? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment