# Association

**URL:** <https://www.ruby-forum.com/t/association/140881>\
**Category:** Rails\
**Created:** [June 19, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/association/140881 "2008-06-19T14:03:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [June 19, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/association/140881/1 "2008-06-19T14:03:37Z")

</div>

Suppose i have three tables user,projects,user\_projects.  
their attributes are:  
tablename attributes:  
1)user id(pk),name,email,password  
2)projects id(pk),projectname,start\_date,end\_date  
3)user\_projects id(pk),user\_id,project\_id

their relationship are  
user:  
has\_many:user\_projects  
has\_many:projects,:through =\>:user\_projects

```
projects:
   has_many:user_projects
   has_many:users,:through =>:user_projects

```

user\_projects:  
belongs\_to :user  
belongs\_to :project

suppose i want

```
     @users=User.find(:first,:condition=>["name=?","James"])
      @projects=@users.projects(:all,:condition=>["projectname=?","temp"])

```

but this will all project related to user name james…  
but the condition inside(@users.projects) is not executed,i am  
unable to get the information of projectname temp in which  
james works…  
pls provide some code how i give condition inside it.  
pls help immediately

---

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [June 19, 2008, 2:09pm UTC](https://www.ruby-forum.com/t/association/140881/2 "2008-06-19T14:09:51Z")

</div>

On Thu, Jun 19, 2008 at 8:03 AM, Subhadip Chakraborty  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> user\_projects:  
> belongs\_to :user  
> belongs\_to :project

The Rails convention is that this table should be named  
projects\_users, i.e., alphabetical order of the tables that form the  
join table is expected.

> suppose i want
> 
> ```
> @users=User.find(:first,:condition=>["name=?","James"])
> @projects=@users.projects(:all,:condition=>["projectname=?","temp"])
> 
> ```

Also, change :condition to :conditions.

Let us know how those changes work.

Craig

---

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [June 19, 2008, 2:21pm UTC](https://www.ruby-forum.com/t/association/140881/3 "2008-06-19T14:21:05Z")

</div>

On Jun 19, 1:08 pm, “Craig D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > suppose i want
> 
> > ```
> > @users=User.find(:first,:condition=>["name=?","James"])
> > @projects=@users.projects(:all,:condition=>["projectname=?","temp"])
> > 
> > ```

And of course here you’re missing the call to find

Fred
