On 10/15/07, Colin Summers
<bladenut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> I read this:
> http://jrhicks.net/Projects/rails/has_many_and_belongs_to_many.pdf
>
> It is from 2005, so some of it has old screenshots (and it looks like
> Windows).
>
> Do I really create that third table on my own? Rails doesn''t
> automagically create it?
>
> I have students and parents. Students can have more than one parent
> and a parent can have more than one student. So I have to create a
> students_parents table to track the connections? How will rails know
> it is that instead of a parents_students table?
>
Actually, rails would want a parents_students table, it puts the model
names in sort order.
And yes, you need to create the table, but nowadays you can use a
migration instead of hand coded sql
CreateParentsStudents < ActiveRecord::Migration
def self.up
create_table :parents_students, :id => false do | t |
t.column :parent_id, :integer
t.column :student_id, :integer
end
end
def self.down
drop_table :parents_students
end
end
--
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.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
-~----------~----~----~----~------~----~------~--~---