[Dbix-class] Schema design query

Dermot paikkos at googlemail.com
Fri Feb 27 15:27:10 GMT 2009


2009/2/27 Rob Kinyon <rob.kinyon at gmail.com>:
> 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.

Thanx Rob I didn't realise that UNIQUE could bound over multiple
columns like that.
Dp.



More information about the DBIx-Class mailing list