| 1 | package Data::MuForm::Field::PrimaryKey; | ||||||||||
| 2 | # ABSTRACT: primary key field | ||||||||||
| 3 | |||||||||||
| 4 | 21 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 21 | extends 'Data::MuForm::Field'; | |||||||||
| 6 | 21 | ▶ | use Types::Standard -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 21 | has 'is_primary_key' => ( isa => Bool, is => 'ro', default => '1' ); | |||||||||
| 10 | 21 | has '+no_value_if_empty' => ( default => 1 ); | |||||||||
| 11 | |||||||||||
| 12 | sub BUILD { | ||||||||||
| 13 | 14 | ▶ | my $self = shift; | ||||||||
|
Subroutine
BUILD: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||
| 14 | 14 | ▶ | if ( $self->has_parent ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 14 | ▶ | if ( $self->parent->has_primary_key ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 0 | push @{ $self->parent->primary_key }, $self; | |||||||||
| 17 | } | ||||||||||
| 18 | else { | ||||||||||
| 19 | 14 | $self->parent->primary_key( [ $self ] ); | |||||||||
| 20 | } | ||||||||||
| 21 | } | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 21 | 1; | |||||||||
| 25 | |||||||||||
| 26 | __END__ | ||||||||||
| 27 | |||||||||||
| 28 | =pod | ||||||||||
| 29 | |||||||||||
| 30 | =encoding UTF-8 | ||||||||||
| 31 | |||||||||||
| 32 | =head1 NAME | ||||||||||
| 33 | |||||||||||
| 34 | Data::MuForm::Field::PrimaryKey - primary key field | ||||||||||
| 35 | |||||||||||
| 36 | =head1 VERSION | ||||||||||
| 37 | |||||||||||
| 38 | version 0.04 | ||||||||||
| 39 | |||||||||||
| 40 | =head1 SYNOPSIS | ||||||||||
| 41 | |||||||||||
| 42 | This field is for providing the primary key for Repeatable fields: | ||||||||||
| 43 | |||||||||||
| 44 | has_field 'addresses' => ( type => 'Repeatable' ); | ||||||||||
| 45 | has_field 'addresses.address_id' => ( type => 'PrimaryKey' ); | ||||||||||
| 46 | |||||||||||
| 47 | Do not use this field to hold the primary key of the form's main db object (model). | ||||||||||
| 48 | That primary key is in the 'model_id' attribute. | ||||||||||
| 49 | |||||||||||
| 50 | =head1 AUTHOR | ||||||||||
| 51 | |||||||||||
| 52 | Gerda Shank | ||||||||||
| 53 | |||||||||||
| 54 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 55 | |||||||||||
| 56 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||
| 57 | |||||||||||
| 58 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 59 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||