Thanks ... I''m using SQLite3 and maybe table now looks like this:
courses_teachers (
course_id integer,
teacher_id integer,
primary key(course_id,teacher_id));
When I try to create a duplicate I get this error message:
ActiveRecord::StatementInvalid in Teacher#add
columns course_id, teacher_id are not unique: INSERT INTO
courses_teachers (''teacher_id'', ''course_id'')
VALUES (''1'', ''1'')
What''s the proper (user friendly) way to handle this exception?
On 4/21/05, Gavin Kistner <gavin-XtLdkLkwz3ZWk0Htik3J/w@public.gmane.org>
wrote:> On Apr 20, 2005, at 5:09 PM, Keith Donaldson wrote:
> > Here is the schema that I am working with:
> >
> > courses -> courses_teachers <- teachers
> >
> > I want to ensure that a teacher is not assigned the same course more
> > than once.
>
> Although there may be a more rails-happy solution, if courses_teachers
> is a table with two-columns only, with the combination used as the
> primary key, it will not be possible to insert a duplicate row.
>
>