[Dbix-class] add_unique_constraint

Ascii King tech at swattermatter.com
Thu Jun 4 15:12:41 GMT 2009


Pardon me, I am not a strong Perl programmer.  If I want to check for a 
unique username before submitting, I would do something like the 
following? (Please pardon my Catalyst format. It's all I know.)

if ($result->model('DB::Account')->find({username=>$submitted_username}) {
    # Then it is a duplicate.
    # Return an error
} elseif {
    # Not a duplicate, go ahead and submit it.
}

I'm not familair with die + eval.   My concern is that I would need to 
do this for every column that is supposed to be unique. This means I 
would need to make a call for each one?

Rob Kinyon wrote:
> On Thu, Jun 4, 2009 at 10:29, Ascii King <tech at swattermatter.com> wrote:
>   
>> 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?
>>     
>
> Using your favorite exception handling method, yes. I personally don't
> like Exception::Class, but others do. I like die + eval - simple and
> clean.
>
>   



More information about the DBIx-Class mailing list