Skip to content

Instantly share code, notes, and snippets.

@stonegao
Created March 30, 2009 06:43
Show Gist options
  • Save stonegao/87664 to your computer and use it in GitHub Desktop.
Save stonegao/87664 to your computer and use it in GitHub Desktop.
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