[Dbix-class] Schema design query

Marcello Romani mromani at ottotecnica.com
Fri Feb 27 13:44:01 GMT 2009


Dermot ha scritto:
> 2009/2/27 Rob Kinyon <rob.kinyon at gmail.com>:
>> This requirement would have a cds table, a genres table, and a
>> many-to-many join table. That join table would have ( cd_id, genre_id
>> ). Look up many_to_many as a relationship.
>>
>> Rob
> 
> I think the penny might have dropped.
> 
> The join table has, as you say, 2 columns (cd_id and genre_id).
> However neither column is set as UNIQUE so you can have multiple
> instances of cd_id thereby a single CD might appear more than once,
> creating the many_to_many. Cool.

In think you should set UNIQUE(cd_id, genre_id).

> 
> Would both these column be set as PK, as in the tutorials user_roles table?
> Thanx,
> Dp.

The PK would be, in theory, formed by both columns.
But IMHO it's easier if you add an 'id' column which would act as PK, 
and just set the UNIQUE constraint on the other two columns, so it's 
easier to refer to the cd<->category associations from a CRUD app.

> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
> 


-- 
Marcello Romani



More information about the DBIx-Class mailing list