add _new flag to Crud objects
This flag allows you to know when an object has been newly-created, so you can check in the BUILD sub and perform appropriate actions.
This commit is contained in:
parent
664e7686c6
commit
6dfeb6ef1a
1 changed files with 7 additions and 0 deletions
|
|
@ -54,6 +54,12 @@ has _dirty => (
|
||||||
default => 0,
|
default => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# True if the object was created by this instance
|
||||||
|
has _new => (
|
||||||
|
is => 'ro',
|
||||||
|
default => 0,
|
||||||
|
);
|
||||||
|
|
||||||
sub _now {
|
sub _now {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return WebGUI::DateTime->new($self->session)->toDatabase;
|
return WebGUI::DateTime->new($self->session)->toDatabase;
|
||||||
|
|
@ -103,6 +109,7 @@ around BUILDARGS => sub {
|
||||||
$data->{sequenceNumber} = $sequenceNumber;
|
$data->{sequenceNumber} = $sequenceNumber;
|
||||||
$data->{$tableKey} = $data->{id} || $session->id->generate;
|
$data->{$tableKey} = $data->{id} || $session->id->generate;
|
||||||
$data->{_dirty} = 1;
|
$data->{_dirty} = 1;
|
||||||
|
$data->{_new} = 1;
|
||||||
|
|
||||||
return $class->$orig($data);
|
return $class->$orig($data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue