[Dbix-class] Schema design query

Rob Kinyon rob.kinyon at gmail.com
Fri Feb 27 15:21:21 GMT 2009


On Fri, Feb 27, 2009 at 10:10, Dermot <paikkos at googlemail.com> wrote:
>> In think you should set UNIQUE(cd_id, genre_id).
>
> Am I missing something? If the cd_id field is UNIQUE then, unless I'm
> mistaken, there can only ever be one instance of a CD in the join
> table so I wouldn't be able to represent that one CD belongs to many
> genre's. I thought I wanted:
>
> cd_genres
> 1|1
> 1|4
> 2|1
> 3|4
> 3|5
>
> CD_1 belongs to genre_id 1 and 4; CD_2 just to genre_id 1; CD_3 to
> genre_id 4 and 5. I think a has_many accessor on the CDs.

Yes, you are missing something. UNIQUE( x, y ) means that the
combination of X and Y must be unique. It's a mutli-column constraint.
So, you couldn't have two rows with cd_id=1, genre_id=2. But, your
example list would be just fine.

Rob



More information about the DBIx-Class mailing list