Association

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"])
      @[email protected](: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

On Thu, Jun 19, 2008 at 8:03 AM, Subhadip Chakraborty
[email protected] 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"])
     @[email protected](:all,:condition=>["projectname=?","temp"])

Also, change :condition to :conditions.

Let us know how those changes work.

Craig

On Jun 19, 1:08 pm, “Craig D.” [email protected]
wrote:

suppose i want

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

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

Fred