Created
March 30, 2009 06:43
-
-
Save stonegao/87664 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
with_options :order => 'created_at', :class_name => 'Comment' do |post| | |
post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all | |
post.has_many :unapproved_comments, :conditions => ['approved = ?', false] | |
post.has_many :all_comments | |
end | |
#You can nest with_options blocks, and you can even use the same name for the block parameter each time. E.g.: | |
class Product | |
with_options :dependent => :destroy do |product| | |
product.with_options :class_name => 'Media' do |product| | |
product.has_many :images, :conditions => {:content_type => 'image'} | |
product.has_many :videos, :conditions => {:content_type => 'video'} | |
end | |
product.has_many :comments | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment