# Using collection\<\< on has\_many with :conditions

**URL:** <https://www.ruby-forum.com/t/using-collection-on-has-many-with-conditions/165963>\
**Category:** Rails\
**Created:** [April 20, 2009, 12:09pm UTC](https://www.ruby-forum.com/t/using-collection-on-has-many-with-conditions/165963 "2009-04-20T12:09:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 20, 2009, 12:09pm UTC](https://www.ruby-forum.com/t/using-collection-on-has-many-with-conditions/165963/1 "2009-04-20T12:09:24Z")

</div>

Hi.

I have a has\_many relation with a hashed condition, taking from the RI  
doc:

:conditions  
Specify the conditions that the associated objects must  
meet in order to be included as a WHERE SQL fragment, such  
as price \> 5 AND name LIKE ‘B%’. Record creations from the  
association are scoped if a hash is used. has\_many :posts,  
:conditions =\> {:published =\> true} will create published  
posts with @blog.posts.create or @blog.posts.build.

I wonder why the behaviour of @blog.posts\<\< is not also modified when  
using hashed conditions. The thing is when I have :conditions =\>  
{:published =\> true}

and issue @blog.posts.create(:published =\> false) will result in a new  
(published) post, i.e. it will override the :published attributes,  
the same holds for @blog.posts.build(:published =\> false), but when I  
do a @blog.posts \<\< Post.new(:published =\> false), it will not be  
overruled by my condition, it will not even fail my condition. It will  
simply end up in the database outside the scope of the condition.

Is this a design decision (of the has\_many :condition attribute)? or  
is this actually a bug/feature request?

Jarl
