First I want to say that I posted a question a while back on linking two tables together and I got quite a few responses all of which were extremely helpful. Thank you the entire forum as you''ve been a big help with everything I''ve learned so far. I do have one more question though. I Am trying to build a product database with each of our jobsites. I may have a construction job that will use a certain type of lamp (which will be in that database) And I want to be able to assign that lamp to another job as well, so we have more than one job using the same type of lamp. How do I go about assigning multiple jobsites to a database entry? The point of this application is that I want to see all the jobs that have used a gold lamp. Thanks Chris -- 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 -~----------~----~----~----~------~----~------~--~---
If I''m reading this right, you want a many-to-many relationship between Products and Jobsites. To do this, you''ll want a simple ''join'' table like this id int... jobsite_id int product_id int which holds an entry for each product used at each site. This table has a one-to-many relationship with each of the other tables. For your gold lamp query, do SELECT * FROM josites j INNER JOIN products_jobsites p_j ON j.id = p_j.jobsite_id INNER JOIN products p ON p_j.product_id = p.id WHERE p.name like ''Gold Lamp''; That what you need? Jason elitegoodguy wrote:> First I want to say that I posted a question a while back on linking two > tables together and I got quite a few responses all of which were > extremely helpful. Thank you the entire forum as you''ve been a big help > with everything I''ve learned so far. > > I do have one more question though. > > I Am trying to build a product database with each of our jobsites. I > may have a construction job that will use a certain type of lamp (which > will be in that database) And I want to be able to assign that lamp to > another job as well, so we have more than one job using the same type of > lamp. > > How do I go about assigning multiple jobsites to a database entry? The > point of this application is that I want to see all the jobs that have > used a gold lamp. > > Thanks > Chris > > -- > 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 -~----------~----~----~----~------~----~------~--~---
On 9/18/06, jnorris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > If I''m reading this right, you want a many-to-many relationship between > Products and Jobsites. To do this, you''ll want a simple ''join'' table > like this > > id int... > jobsite_id int > product_id intWarning here; join tables don''t generally have their own id. -- More software projects have gone awry for lack of calendar time than for all other causes combined. -- Fred Brooks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I have a slightly different need: I want to create tables recording how network devices are linked. i.e. devA is connected to devB, devA is connected to devC, devD is connected to devE devE is connected to devF etc I''m thinking I need two tables: devices - id int - name string links - id int - dev1_id int - dev2_id int My problem is I''m not sure how to model this in rails. Would acts_as_list or acts_like_tree work here? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Campbell wrote:> On 9/18/06, jnorris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >...> > Warning here; join tables don''t generally have their own id. >I fact I created a join table with an id column once. It worked ... sort of. Some db entries it would create, others it wouldn''t. Drove me nuts until I went back and read that join tables <b>should</b> not have a primary id field. Worked much better once I deleted the primary id column. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ah yes, you just use the PRIMARY KEY(jobsite_id, product_id); syntax. On 9/18/06, Michael Campbell <michael.campbell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 9/18/06, jnorris <jasonmnorris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > If I''m reading this right, you want a many-to-many relationship between > > Products and Jobsites. To do this, you''ll want a simple ''join'' table > > like this > > > > id int... > > jobsite_id int > > product_id int > > Warning here; join tables don''t generally have their own id. > > -- > More software projects have gone awry for lack of calendar time than > for all other causes combined. -- Fred Brooks > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---