Carl Franks wrote:
2009/6/3 Ascii King <t...@swattermatter.com>:
I am a rookie programmer trying to set up a web database. I am having
trouble understanding how to get the add_unique_constraint working. I am
using Catalyst and FormFu and I cannot get the method working as i expect. I
added the following line to my Schema file:

# Created by DBIx::Class::Schema::Loader v0.04004 @ 2009-05-14 10:18:31
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5sD0bi0DMi9SwUz0z7Jt7A

__PACKAGE__->add_unique_constraint(username => [ qw/username/ ]);


But, it does not seem to affect my code at all.  I would like each username
to be unique in the system and prevent dupklicates from being entered. i am
using both an SQLite3 database and a separate instance on a MS SQL Server.

add_unique_constraint() is used by deploy() to add the constraint to
the SQL used to create the database table.

It won't do any checks when you're INSERTing / UPDATEing data, because
the constraint should be in the database's schema.

So, as you're using DBIx::Class::Schema::Loader this won't do what
you're expecting it to do - you need to manually add the constraint
to the database (or use DBIC's deploy() or update() ).

Carl

_______________________________________________
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


Thanks for the help. One more question, though. The preferred method for handling unique columns is to let the database manage them and then just trap the error message using Exception::Class?

_______________________________________________
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

Reply via email to