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_nullable => 0,
|
||||
},
|
||||
"customer_id" => {
|
||||
"entity_id" => {
|
||||
data_type => "integer",
|
||||
is_foreign_key => 1,
|
||||
is_nullable => 1,
|
||||
},
|
||||
"organisation_id" => {
|
||||
data_type => "integer",
|
||||
is_foreign_key => 1,
|
||||
is_nullable => 1,
|
||||
is_nullable => 0,
|
||||
},
|
||||
"email" => {
|
||||
data_type => "text",
|
||||
|
@ -51,59 +46,21 @@ __PACKAGE__->add_columns(
|
|||
},
|
||||
passphrase_check_method => 'check_password',
|
||||
},
|
||||
"is_admin" => {
|
||||
data_type => "boolean",
|
||||
default_value => \"0",
|
||||
is_nullable => 0,
|
||||
},
|
||||
);
|
||||
|
||||
__PACKAGE__->set_primary_key("id");
|
||||
|
||||
__PACKAGE__->add_unique_constraint(["customer_id"]);
|
||||
|
||||
__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(
|
||||
"customer",
|
||||
"Pear::LocalLoop::Schema::Result::Customer",
|
||||
{ "foreign.id" => "self.customer_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 },
|
||||
"entity",
|
||||
"Pear::LocalLoop::Schema::Result::Entity",
|
||||
"entity_id",
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
|
@ -113,13 +70,6 @@ __PACKAGE__->has_many(
|
|||
{ 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(
|
||||
"feedback",
|
||||
"Pear::LocalLoop::Schema::Result::Feedback",
|
||||
|
@ -144,22 +94,20 @@ sub generate_session {
|
|||
sub name {
|
||||
my $self = shift;
|
||||
|
||||
if ( defined $self->customer_id ) {
|
||||
return $self->customer->display_name;
|
||||
} elsif ( defined $self->organisation_id ) {
|
||||
return $self->organisation->name;
|
||||
if ( defined $self->entity->customer ) {
|
||||
return $self->entity->customer->display_name;
|
||||
} elsif ( defined $self->entity->organisation ) {
|
||||
return $self->entity->organisation->name;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# TODO Deprecate this sub?
|
||||
sub type {
|
||||
my $self = shift;
|
||||
|
||||
if ( defined $self->customer_id ) {
|
||||
return "customer";
|
||||
}
|
||||
return "organisation";
|
||||
return $self->entity->type;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Reference in a new issue