Search on variable-length array of values?

I am a bit stuck with the following problem, and would welcome

I have two tables, e.g. “things” and “properties”, with one line of of
things corresponding to one line of properties, and vice-versa, and 70
elements per line of properties. Users want to be able to find all
things where their favourite elements in the properties table are not
null, and the number of things they are interested in is variable. I
have put the list of elements on a page where users may select those
they are interested in and this returns a hash containing only those
they have selected, with values set to 1.

The only method I can come up with is to construct a string along the
lines of:

“select thing_id from properties where A is not null and B is not null
and C is not null…”

…etc., then use this with Property.find_by_sql. Then, I’d have to use
the output of that to do another search on things.

Is there any better way to do this with find? E.g something like:

@things = thing.find(:All, :conditions=>[“properties.? is not null”,
array_of_interesting_elements], :include => :property)

This doesn’t work, of course, but perhaps there is something similar
that might?

how about

@things = Thing.find_by_sql(“select t.* from things t, properties p
where #{@long_not_null_string} =”)

that might work…

meep wrote:

@things = Thing.find_by_sql(“select t.* from things t, properties p
where #{@long_not_null_string} =”)

D’oh! :blush:
You’re right - that works perfectly. Many thanks.