Re: Re: howto implement a join table

Chris Kottom
Tue, 15 Feb 2011 12:47:08 -0000

I would do:

   1. rails generate model worker [ definition of model attributes ]
   2. Modify migration file for workers table as needed
   3. Modify app/model/worker.rb to add has_and_belongs_to_many :courses
   4. rails generate model course [ definition of model attributes ]
   5. Modify migration file for course table as needed
   6. Modify app/model/course.rb to add has_and_belongs_to_many :workers
   7. rails generate migration create_course_workers_join_table
   8. Edit this migration to create a new table with the necessary foreign
   keys and following the Rails standard naming conventions (plurals of each
   table name, in A-Z order).

See
http://guides.rubyonrails.org/association_basics.html#creating-join-tables-for-has_and_belongs_to_many-associations
if
you need something more.

On Tue, Feb 15, 2011 at 12:26 PM, Colin Law
<clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:

> On 15 February 2011 10:50, rogi
<patrik.keller-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
> >
> > On 15 Feb., 11:29, Lorenzo Brito Morales
<lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > wrote:
> >> With Active record , its already link it, i mean, whit
@worker.courses
> >>  you have a collection of what courses has a worker take it.
> >> With scaffold is to set up custom code to controller/view/model .
> >
> > I dont now about active record! I mean @worker.course doesn''t
work yet
> > at my project.
> > I just have the two tables and now i try to easily find a way to get
> > the html pages, table structures and relations that allow for linking
> > the courses to the workers?
> > I''m thinking of a manageWorkersCourses.html that
let''s me select a
> > worker and then add a course from a dropdown list.
> > On the manageWorkersCourses.html page all the courses of the selected
> > worker get listed.
>
> It seems that maybe you are just starting on Rails and have not yet
> acquired some of the basic principles.  I suggest you work through the
> Rails Guides and some tutorials (try http://railsforzombies.org/ and
> railstutorial.org ).  Make sure that any tutorial you use is for the
> correct major version of Rails (2 or 3).  I suggest that you should be
> using Rails 3 if you are not already.
>
> Colin
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.