From 7fc7dd76494742208c9c37422700b795576f55fd Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 4 Nov 2008 15:44:34 +0000 Subject: [PATCH] Crud create() for specific id (#9035) --- lib/WebGUI/Crud.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Crud.pm b/lib/WebGUI/Crud.pm index ecbabe46d..87574bc3f 100644 --- a/lib/WebGUI/Crud.pm +++ b/lib/WebGUI/Crud.pm @@ -119,7 +119,7 @@ These methods are available from this package: #------------------------------------------------------------------- -=head2 create ( session, [ properties ]) +=head2 create ( session, [ properties ], [ options ]) Constructor. Creates a new instance of this object. Returns a reference to the object. @@ -131,10 +131,18 @@ A reference to a WebGUI::Session or an object that has a session method. If it's The properties that you wish to create this object with. Note that if this object has a sequenceKey then that sequence key must be specified in these properties or it will throw an execption. See crud_definition() for a list of all the properties. +=head3 options + +A hash reference of creation options. + +=head4 id + +A guid. Use this to force the row's table key to a specific ID. + =cut sub create { - my ($class, $someObject, $data) = @_; + my ($class, $someObject, $data, $options) = @_; # dynamic recognition of object or session my $session = $someObject; @@ -176,7 +184,7 @@ sub create { $sequenceNumber++; # create object - my $id = $db->setRow($tableName, $tableKey, {$tableKey=>'new', dateCreated=>$now, sequenceNumber=>$sequenceNumber}); + my $id = $db->setRow($tableName, $tableKey, {$tableKey=>'new', dateCreated=>$now, sequenceNumber=>$sequenceNumber}, $options->{id}); my $self = $class->new($someObject, $id); $self->update($data); return $self;