I have an
app run ning Rails 2.3 with Ruby 1.8.7.
Upgrading is not in the cards for a while.
I am trying to make it database agnostic so I want
to eliminate the use of find _by_sql.
I have got it down to only one find left but I have not
been able to figure out how to do this by a find.
I have two tables:
Reservation belongs_to
:space
int space_id
date startdate
date enddate
and a bunch of other
stuff
Space - has many reservations
containin g
a bunch of stuff ab out spaces
I
want to fetch the spaces which are not used by a reservation meeting certain conditions.
The
current find is:
all_spaces =
find_by_sql("SELECT * FROM spaces
WHERE
id NOT IN (SELECT
space_id FROM reservations
WHERE
enddate >
'#{start_dt}'
AND startdate
< '#{end_dt}')
")
Is
there a way I can just use a Space.all …?
Norm