[LRUG] Deleting data that's in use

Jason Cale jason.cale at mac.com
Wed Nov 12 11:03:14 PST 2008


This is essentially what acts_as_paranoid plugin does ..

http://github.com/technoweenie/acts_as_paranoid/tree/master

It is a basic drop in for the functionality .. and will scope your  
find(:all) (etc) calls in a similar way to what Tom outlined below.

Jase.

On 12 Nov 2008, at 18:45, Tom Ward wrote:

> A common solution is to have a datetime 'deleted_at' column in your
> database and set that when the user deletes a company.  Then in the
> UI, only show companies where deleted_at is null.  In later versions
> of rails, you could use a named scope to restrict your queries, such
> as:
>
> class Company < ActiveRecord::Base
>    named_scope :visible, :conditions => {:deleted_at => false}
> end
>
> class CompaniesController < ApplicationController
>  def show
>    @company = Company.visible.find(params[:id])
>  end
> end
>
> Accessing the company through a relationship (such as from the
> delivery note) will work as before.
>
> Tom
>
> 2008/11/12 Andrew Stewart <boss at airbladesoftware.com>:
>> Hi El Rug,
>>
>> (This isn't a Ruby language question; it's more of an interaction  
>> design
>> question.)
>>
>> In my current app users manage the loaning of stuff to companies.   
>> It's a
>> bit like a library loaning books to customers.  Every loan  
>> generates a
>> delivery note which records what was lent to whom.
>>
>> Today a user wanted to delete one of the companies from the  
>> system.  This
>> company has received a number of loans in the past.  The deletion
>> (correctly) failed because a foreign key constraint in the database  
>> said no,
>> you can't delete that company because it's referenced by several  
>> delivery
>> notes.  So the company is still there, causing much rolling of eyes  
>> and
>> shrugging of shoulders by the user.
>>
>> What's the best way to handle this?
>>
>> I'm thinking that deleting the company would indeed be wrong  
>> because it
>> breaks the delivery notes in question.  Perhaps when the user  
>> clicks delete,
>> the system should "soft delete" it (if there are any delivery notes
>> referring to it, otherwise delete as normal) -- i.e. freeze the  
>> company's
>> attributes, don't show it in any list of companies, and don't  
>> delete it.
>>
>> Is this a good idea?  Are there better ideas?  I'd value your  
>> thoughts.
>>
>> Thanks and regards,
>>
>> Andy Stewart
>>
>> -------
>> http://airbladesoftware.com
>>
>>
>>
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org




More information about the Chat mailing list