# Condition on join table on a has\_many :through isn't created

**URL:** <https://www.ruby-forum.com/t/condition-on-join-table-on-a-has-many-through-isnt-created/143180>\
**Category:** Rails\
**Created:** [July 16, 2008, 1:07am UTC](https://www.ruby-forum.com/t/condition-on-join-table-on-a-has-many-through-isnt-created/143180 "2008-07-16T01:07:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 16, 2008, 1:07am UTC](https://www.ruby-forum.com/t/condition-on-join-table-on-a-has-many-through-isnt-created/143180/1 "2008-07-16T01:07:24Z")

</div>

Hi,

i have a Permissions table with rank\_id:integer, group\_id:integer and  
a key:string  
a group model and a rank model.

The group has\_many “virtual permissions” through the join table. Each  
permission type  
is identified by the key in the permissions table with a :condition on  
the has\_many association.

But when i add a association through the has\_many association it  
doesn’t create the  
permissions entry with the right key. It just puts NULL into the  
permissions.key field.

This is my code (the important parts of the models) with a example  
which operation fails.

[http://pastie.org/234328](http://pastie.org/234328)

any ideas?

---

<div class="post-metadata">

**Author:** ![Pascal\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@Pascal\_F](https://www.ruby-forum.com/u/Pascal_F)\
**Post date:** [July 16, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/condition-on-join-table-on-a-has-many-through-isnt-created/143180/2 "2008-07-16T14:54:34Z")

</div>

i wonder if this is a bug or a feature.  
does anyone know if this behaviour is wanted?  
ActiveRecord:Associations has\_many tells me:

:conditions - Specify the conditions that the associated object must  
meet in order to be included as a WHERE SQL fragment, such as  
authorized = 1. \*\* 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. \*\*

this only works for the joined table not for the join table?
