[jifty-devel] How to delete a record through an action

Stanislav Sinyagin ssinyagin at yahoo.com
Fri Feb 15 10:43:21 EST 2008


I'm a bit stuck with the use of Actions.

I want to list the records in a table, and at the end of each row place 
a link "Delete" which would delete the record.

The code follows. When I click "Delete", the debug log says the corresponding
action is found, but when the Model object's "delete" method is called, 
it's called in an object that was not loaded from the database, and therefore
its ID is unknown, and basically the deletion is not happening:




    my $requests = new Toponet::Model::TraceRequestCollection
        (current_user => Jifty->web->current_user());

    $requests->limit( column    => 'startDevice',
                      operator  => '=',
                      value     => $deviceID );
    my $reqs = $requests->items_array_ref();

    if( scalar(@{$reqs}) > 0 )
    {
        my $delAction = Jifty->web->new_action
            (class => 'Toponet::Action::DeleteTraceRequest',
             moniker => 'delete_trace_request');

</%perl>
     <P>Existing trace requests:</P>
     <TABLE>
     <TR>
       <TH>Request ID</TH>
       <TH>Submitted</TH>
       <TH>Status</TH>
       <TH>Target IP</TH>
       <TH>Completed</TH>
       <TH>Results</TH>
       <TH>Action</TH>
     </TR>
     
%       foreach my $request
%           (sort {$a->id() <=> $b->id()} @{$reqs}) {

     <TR>  
       <TD><% $request->id() %></TD>
       <TD><% scalar(localtime( $request->timeCreated() )) %></TD>
       <TD><% $request->status() %></TD>
       <TD><% $request->targetValue() %></TD>
       <TD><% $request->status() eq 'complete' ?
                scalar(localtime( $request->timeComplete() )) : '' %></TD>
       <TD><% $request->status() eq 'complete' ?
               '<A HREF="/show_trace_results.html?traceID=' . $request->id() .
               '">view</A>' : '' |n %></TD>
       <TD>
       <% Jifty->web->form->start %>
       <% Jifty->web->link
       (label  => 'Delete',
        as_link => 1,
        onclick => {
            submit => $delAction,
            args => { id => $request->id() },
            refresh_self => 1 }) %></TD>
       <% Jifty->web->form->end %>
     </TR>

%       }     
     </TABLE>
%    }







More information about the jifty-devel mailing list