HTML::...Unique(3pm)
π HTML::...Unique(3pm) π
okay bestie, gather round, because this is the manpage for HTML::FormFu::Constraint::DBIC::Unique β the Perl module that keeps your database from having two of the same thing, no cap. It's a constraint for HTML::FormFu::Model::DBIC and honestly? iconic behaviour.
VERSION: version 2.03 β¨ (yes, we stan a numbered release)
π SYNOPSIS π
here's the vibe β you either wire it up in code:
$form->stash->{schema} = $dbic_schema; # DBIC schema
$form->element('text')
->name('email')
->constraint('DBIC::Unique')
->resultset('User')
;
$form->stash->{context} = $c; # Catalyst context
$form->element('text')
->name('email')
->constraint('DBIC::Unique')
->model('DBIC::User')
;
$form->element('text')
->name('user')
->constraint('DBIC::Unique')
->model('DBIC')
->resultset('User')
;
or in a config file:
---
elements:
- type: text
name: email
constraints:
- Required
- type: DBIC::Unique
model: DBIC::User
- type: text
name: user
constraints:
- Required
- type: DBIC::Unique
model: DBIC::User
column: username
literally three ways to do the same thing and a config-file version too. pick your fighter π
π¦ DESCRIPTION π¦
it checks if the input value exists in a DBIC ResultSet. that's it, that's the whole job. if it's already in there, the constraint is not having it. periodt.
π METHODS π
π model
Arguments: $string β a Catalyst model name like 'DBIC::User'
π resultset
Arguments: $string β a DBIC resultset name like 'User'
π self_stash_key
a reference to a key in the form stash. if this key exists, the constraint will check if the id matches the one of this element, so that you can use your own name. main character energy, honestly π«Ά
π id_field
use this key to define reference field which consist of primary key of resultset. if the field exists (and $self_stash_key not defined), the constraint will check if the id matches the primary key of row object:
---
elements:
- type: Hidden
name: id
constraints:
- Required
- type: Text
name: value
label: Value
constraints:
- Required
- type: DBIC::Unique
resultset: ControlledVocab
id_field: id
π others
use this key to manage unique compound database keys which consist of more than one column. for example, if a database key consists of 'category' and 'value', use a config file such as this:
---
elements:
- type: Text
name: category
label: Category
constraints:
- Required
- type: Text
name: value
label: Value
constraints:
- Required
- type: DBIC::Unique
resultset: ControlledVocab
others: category
two columns, one constraint, zero duplicates. slay π§
π method_name
name of a method which will be called on the resultset. the method is passed two argument; the value of the field, and the primary key value (usually id) of the record in the form stash (as defined by self_stash_key). an example config might be:
---
elements:
- type: text
name: user
constraints:
- Required
- type: DBIC::Unique
model: DBIC::User
method_name: is_username_available
π₯ SEE ALSO π₯
- is a sub-class of, and inherits methods from
HTML::FormFu::Constraint HTML::FormFu::FormFu
π AUTHOR π
Jonas Alves <jgda@cpan.org>
πΈ LICENSE πΈ
this library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. π
okay and the lil footer tea: this is perl v5.36.0, dated 2022-11-20, and the page you just read is HTML::...Unique(3pm). that's a wrap bestie, go make your database exclusive πβ¨π
π¦ where this page comes from
- debian bookworm: libhtml-formfu-model-dbic-perl 2.03-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhtml-formfu-model-dbic-perl 2.03-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-formfu-model-dbic-perl 2.03-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-formfu-model-dbic-perl 2.03-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-formfu-model-dbic-perl 2.03-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms