What you're describing is a many to many relationship. What you've done is just a one to many relationship.
In a many to many relationship, you define many independent records on each side and use a join table to create links from one to another.
In a one to many relationship, each record on the one side is independent while each record on the many side is dependent on the one that it is linked to.
Examples stemming from your questions:
many to many: Each Student can have many awards, but do not need to be linked to an award to have meaning. Each award can be earned by many students, but do not need to be linked to an student to have meaning. StackOverflow's badges are a perfect example of this.
one to many: Each student can have many awards but do not need to be linked to an award to have meaning. Each award is unique to only one student.
How to turn your relationship to a many to many relationship:
- create an awardings table that has
student_id
and award_id
columns.
- remove the student_id column from the awards table.
Inform ActiveRecord of the relationships.
class Student < ActiveRecord::Base
has_many :awardings
has_many :awards, :through => :awardings
...
end
class Awarding < ActiveRecord::Base
belongs_to :student
belongs_to :award
end
class Award < ActiveRecord::Base
has_many :awardings
has_many :students, :through => :awardings
end
Update your forms to reflect the changes.
Use either a multple select box, or a series of checkboxes to manage many at once. There are many tutorials out there about this. This Railscast episode is way out of date but is a good start.
P.S. Your more likely to get answers if you don't check the community wiki box. Community wikis are for non-technical questions, where the answers are likely to be improved by several users.