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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Thu, Jun 19, 2008 at 8:03 AM, Subhadip Chakraborty <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> user_projects: > belongs_to :user > belongs_to :projectThe 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 19, 1:08 pm, "Craig Demyanovich" <cdemyanovich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jun 19, 2008 at 8:03 AM, Subhadip Chakraborty > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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=-yt2nUqeIc6XxyJVTx5GGxQ@public.gmane.org(:all,:condition=>["projectname=?","temp"]) >And of course here you''re missing the call to find Fred> Also, change :condition to :conditions. > > Let us know how those changes work. > > Craig--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---