I’m no good at SQL and I have a question that will hopefully be fairly
easy to answer.
I’m using acts_as_paranoid which instead of deleting a record adds a
deleted_at column with the datetime the row was deleted. I want to have
a find_by_sql filter out any row where deleted_at is not null.
I have (at least the relevant parts): #a couple working filters here.
filters << “crs.deleted_at IS NOT NULL” # THIS DOES NOT WORK
filters = ‘WHERE ’ + filters.join(’ AND ') unless filters.empty?
direction = ‘DESC’ unless %w{ASC DESC}.include? direction
find_by_sql %{SELECT crs.*,
status.status AS status_status
FROM crs
LEFT OUTER JOIN status on status.id = crs.status_id
#{filters.to_s unless filters.empty?}
ORDER BY crs.#{order_by} }
end
Yeah that helped. I only had to remove one word from my statement:
filters << “crs.deleted_at IS NOT NULL”
became
filters << “crs.deleted_at IS NULL”
I wanted to filter OUT the crs that where deleted_at was null, not the
opposite. Thanks for your help, sometimes the obvious escapes me until
someone smacks me in the head with it
-Marcus
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.