Closed KES777 closed 4 years ago
I am not sure I follow what is the bug in here, please step back and explain detailed what you are trying to achieve and what is the error you are getting.
The person
has related passwords
and emails
tables.
here I create at once person/email/password.
As workaround I create password manually:
my $pw = $user->create_related( person_passwords => {
password => ''
});
Then hash it:
$pw->password( $v->param( 'password' ) );
$pw->update;
This is not actually a bug, but a side effect in how your DB is designed.
Your Person model doesn't know anything about password columns during its ->create(...)
time so that it could effectively process the encoded columns.
How it does now know if PersonPassword
defines this column?
a=> \d person_password
Table "public.person_password"
Column | Type | Collation | Nullable | Default
-----------+-----------------------+-----------+----------+-------------------------------
id | integer | | not null | nextval('person_password_id_se
person_id | integer | | not null |
password | character varying(40) | | not null |
Indexes:
"person_password_pkey" PRIMARY KEY, btree (id)
package HyperMouse::Schema::Result::PersonPassword;
use utf8;
use Modern::Perl;
use parent 'HyperMouse::Schema::NoTemporalResult';
my $X = __PACKAGE__;
$X->table("person_password");
$X->add_columns(
id => {
data_type => "integer",
is_auto_increment => 1,
retrieve_on_insert => 1,
},
person_id => {
data_type => "integer",
is_foreign_key => 1,
},
# password => { data_type => "varchar", size => 40 }, # See below
);
=head1 PRIMARY KEY
=over 4
=item * L</id>
=back
=cut
$X->set_primary_key("id");
=head1 RELATIONS
=head2 person
Type: belongs_to
Related object: L<HyperMouse::Schema::Result::Person>
=cut
require HyperMouse::Schema::Result::Person;
my $Person = 'HyperMouse::Schema::Result::Person';
$X->belongs_to(
person => $Person,
{ id => "person_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "NO ACTION" },
);
$X->load_components(qw/EncodedColumn/);
$X->add_columns(
'password' => {
data_type => 'varchar',
size => 40,
encode_column => 1,
encode_class => 'Digest',
encode_args => { algorithm => 'SHA-1', format => 'hex' },
encode_check_method => 'check_password'
}
);
1;
Also person
knows about person_password
package HyperMouse::Schema::Result::Person;
use utf8;
use Modern::Perl;
use parent 'HyperMouse::Schema::NoTemporalResult';
my $X = __PACKAGE__;
$X->table("person");
$X->add_columns(
country_id => {
data_type => 'integer',
is_nullable => 1,
},
owner_id => {
data_type => 'integer',
is_nullable => 1,
},
id => {
data_type => "integer",
is_auto_increment => 1,
retrieve_on_insert => 1,
extra => { unsigned => 1 },
},
link_1c_id => {
data_type => 'text',
is_nullable => 1,
},
first_name => { data_type => "varchar", size => 64 },
middle_name => { data_type => "varchar", is_nullable => 1, size => 64 },
last_name => { data_type => "varchar", size => 64 },
birth_date => {
data_type => 'date',
is_nullable => 0,
default_value => "2000-01-01 00:00:00", # Only for first migration
},
language_id => {
data_type => "integer",
is_foreign_key => 1,
},
timezone => { data_type => "varchar", size => 32 },
datetime_format_id => {
data_type => "integer",
is_foreign_key => 1,
},
gender => {
data_type => "boolean",
is_nullable => 1,
},
comment => {
data_type => 'text',
is_nullable => 1,
},
);
=head1 PRIMARY KEY
=over 4
=item * L</id>
=back
=cut
$X->set_primary_key("id");
=head1 RELATIONS
=head2 datetime_format
Type: belongs_to
Related object: L<HyperMouse::Schema::Result::DatetimeFormat>
=cut
require HyperMouse::Schema::Result::DatetimeFormat;
my $DatetimeFormat = 'HyperMouse::Schema::Result::DatetimeFormat';
$X->belongs_to(
datetime_format => $DatetimeFormat,
{ datetime_format_id => "datetime_format_id" },
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" },
);
my $C = 'HyperMouse::Schema::Result::Country';
$X->belongs_to( Country => $C, 'country_id' );
require HyperMouse::Schema::Result::Country;
$C->has_many ( Persons => $X, 'country_id' );
=head2 language
Type: belongs_to
Related object: L<HyperMouse::Schema::Result::Language>
=cut
require HyperMouse::Schema::Result::Language;
my $Language = 'HyperMouse::Schema::Result::Language';
$X->belongs_to(
language => $Language,
{ language_id => "language_id" },
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "CASCADE" },
);
=head2 person_emails
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonEmail>
=cut
$X->has_many(
"person_emails",
"HyperMouse::Schema::Result::PersonEmail",
{ "foreign.person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 person_passwords
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonPassword>
=cut
$X->has_many(
"person_passwords",
"HyperMouse::Schema::Result::PersonPassword",
{ "foreign.person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 person_phones
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonPhone>
=cut
$X->has_many(
"person_phones",
"HyperMouse::Schema::Result::PersonPhone",
{ "foreign.person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 person_x_contractors
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonXContractor>
=cut
$X->has_many(
"person_x_contractors",
"HyperMouse::Schema::Result::PersonXContractor",
{ "foreign.person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 person_x_person_child_people
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonXPerson>
=cut
$X->has_many(
"person_x_person_child_people",
"HyperMouse::Schema::Result::PersonXPerson",
{ "foreign.child_person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 person_x_person_parent_people
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonXPerson>
=cut
$X->has_many(
"person_x_person_parent_people",
"HyperMouse::Schema::Result::PersonXPerson",
{ "foreign.parent_person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 person_x_provisioning_agreements
Type: has_many
Related object: L<HyperMouse::Schema::Result::PersonXProvisioningAgreement>
=cut
$X->has_many(
"person_x_provisioning_agreements",
"HyperMouse::Schema::Result::PersonXProvisioningAgreement",
{ "foreign.person_id" => "self.person_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
$X->many_to_many(
"corporations" => "person_x_corporations", "corporation",
);
$X->many_to_many(
"contractors" => "person_x_contractors", "contractor",
);
$X->many_to_many(
"provisioning_agreements" => "person_x_provisioning_agreements", "provisioning_agreement"
);
sub roles {
my( $self ) = @_;
return 'user';
}
1;