[Dbix-class] Views and tables without primary keys

Jonathan Rockway jon at jrock.us
Tue Jul 8 04:13:15 BST 2008


* On Sun, Jul 06 2008, Christopher Laco wrote:
> IvorW wrote:
>> I have an application that uses a view. The application uses
>> DBIx::Class::Schema::Loader, and I get a warning about primary keys,
>> every time I start the app. The application works fine. In fact I get
>> the warning when I use a MySQL database, but not when I use sqlite.
>>
>> I've traced it in the source code to DBIx::Class::Schema::Loader::Base,
>> and I attach a patch which removes the warning. In theory, this warning
>> might be serving some purpose if you had a genuine table that didn't
>> have a primary key, but not for a view. This warning just gets in the way.
>
> I'd say this warning should be kept if your using Loader to generate a
> static schema (files), but it should be removed if you're using a
> dynamic schema (on the fly).

I disagree; I think the warning should be kept regardless.  When you are
generating code from the database, any small change to the database can
affect your code.  For that reason, when your app stops working, you
want as much info printed out as possible.  (Maybe Log::Dispatch or
similar would be more appropriate, so you can turn warnings off... but
since we are just sticking with 'warn', I say keep 'em.)

If you want the warning to shut up, don't use a dynamic schema.  Dynamic
schemas are nice for one-off scripts, but for anything else I would
really make a static schema and let DBIC be the canonical source for the
database definition.  If you are seeing the warning enough to patch the
library, you probably really want a static schema ;)

Regards,
Jonathan Rockway

-- 
print just => another => perl => hacker => if $,=$"



More information about the DBIx-Class mailing list