[LRUG] Deleting data that's in use
Andrew Stewart
boss at airbladesoftware.com
Thu Nov 13 03:57:56 PST 2008
Excellent, thanks for the suggestions. That's exactly what I need.
Regards,
Andy
On 12 Nov 2008, at 19:03, Jason Cale wrote:
> 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
More information about the Chat
mailing list