Updated user to use new Entity table
This commit is contained in:
parent
2954297b35
commit
fd98670333
1 changed files with 16 additions and 68 deletions
|
@ -21,15 +21,10 @@ __PACKAGE__->add_columns(
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
"customer_id" => {
|
"entity_id" => {
|
||||||
data_type => "integer",
|
data_type => "integer",
|
||||||
is_foreign_key => 1,
|
is_foreign_key => 1,
|
||||||
is_nullable => 1,
|
is_nullable => 0,
|
||||||
},
|
|
||||||
"organisation_id" => {
|
|
||||||
data_type => "integer",
|
|
||||||
is_foreign_key => 1,
|
|
||||||
is_nullable => 1,
|
|
||||||
},
|
},
|
||||||
"email" => {
|
"email" => {
|
||||||
data_type => "text",
|
data_type => "text",
|
||||||
|
@ -51,59 +46,21 @@ __PACKAGE__->add_columns(
|
||||||
},
|
},
|
||||||
passphrase_check_method => 'check_password',
|
passphrase_check_method => 'check_password',
|
||||||
},
|
},
|
||||||
|
"is_admin" => {
|
||||||
|
data_type => "boolean",
|
||||||
|
default_value => \"0",
|
||||||
|
is_nullable => 0,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->set_primary_key("id");
|
__PACKAGE__->set_primary_key("id");
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["customer_id"]);
|
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["email"]);
|
__PACKAGE__->add_unique_constraint(["email"]);
|
||||||
|
|
||||||
__PACKAGE__->add_unique_constraint(["organisation_id"]);
|
|
||||||
|
|
||||||
__PACKAGE__->might_have(
|
|
||||||
"administrator",
|
|
||||||
"Pear::LocalLoop::Schema::Result::Administrator",
|
|
||||||
{ "foreign.user_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
__PACKAGE__->belongs_to(
|
||||||
"customer",
|
"entity",
|
||||||
"Pear::LocalLoop::Schema::Result::Customer",
|
"Pear::LocalLoop::Schema::Result::Entity",
|
||||||
{ "foreign.id" => "self.customer_id" },
|
"entity_id",
|
||||||
{
|
|
||||||
is_deferrable => 0,
|
|
||||||
join_type => "LEFT",
|
|
||||||
on_delete => "NO ACTION",
|
|
||||||
on_update => "NO ACTION",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->belongs_to(
|
|
||||||
"organisation",
|
|
||||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
|
||||||
{ "foreign.id" => "self.organisation_id" },
|
|
||||||
{
|
|
||||||
is_deferrable => 0,
|
|
||||||
join_type => "LEFT",
|
|
||||||
on_delete => "NO ACTION",
|
|
||||||
on_update => "NO ACTION",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"pending_organisations",
|
|
||||||
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
|
|
||||||
{ "foreign.submitted_by_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"pending_transactions",
|
|
||||||
"Pear::LocalLoop::Schema::Result::PendingTransaction",
|
|
||||||
{ "foreign.buyer_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->has_many(
|
||||||
|
@ -113,13 +70,6 @@ __PACKAGE__->has_many(
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
|
||||||
"transactions",
|
|
||||||
"Pear::LocalLoop::Schema::Result::Transaction",
|
|
||||||
{ "foreign.buyer_id" => "self.id" },
|
|
||||||
{ cascade_copy => 0, cascade_delete => 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
__PACKAGE__->has_many(
|
__PACKAGE__->has_many(
|
||||||
"feedback",
|
"feedback",
|
||||||
"Pear::LocalLoop::Schema::Result::Feedback",
|
"Pear::LocalLoop::Schema::Result::Feedback",
|
||||||
|
@ -144,22 +94,20 @@ sub generate_session {
|
||||||
sub name {
|
sub name {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if ( defined $self->customer_id ) {
|
if ( defined $self->entity->customer ) {
|
||||||
return $self->customer->display_name;
|
return $self->entity->customer->display_name;
|
||||||
} elsif ( defined $self->organisation_id ) {
|
} elsif ( defined $self->entity->organisation ) {
|
||||||
return $self->organisation->name;
|
return $self->entity->organisation->name;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO Deprecate this sub?
|
||||||
sub type {
|
sub type {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if ( defined $self->customer_id ) {
|
return $self->entity->type;
|
||||||
return "customer";
|
|
||||||
}
|
|
||||||
return "organisation";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Reference in a new issue