Assume I have a class Post. Post has a boolean field 'posted', indicating whether the post has been posted or not. I also have another class, Blog. If I want the blog to have many Posts:
class Blog < ActiveRecord::Base
has_many :posts
has_many :posted_posts, :conditions => {:posted => true}, :class_name => 'Post'
end
Blog.posted_posts.find(:all)
works just as expected. But what if I want to do the following in order to have the blog post it immediately:
Blog.posted_posts.create(:title => 'The Blog Post')
This doesn't automatically alter the condition of :posted to true. This seems odd, and inconsistent since the only way to access this record is from Blog.posts, rather than Blog.posted_posts, where I created it from.
The obvious problem that arises is that if the conditions are not exactly specific about alterations need to be done such as 'date < 2008' the create cannot work with this. I suggest that to patch this, if a hash is being used for conditions it can be used on either a create or a find since the values are specific. Otherwise :conditions only applies to the find and an alternate :create_conditions can be used for creates.