Add'l filtering on HABTM


I have a table “keywords” with a HABTM relationship with “files” in a
legacy MySQL db.

I can find all of the files associated with a keyword in Rails. These
files can be on any of 4 volumes. However, users can have restrictions
on which volumes they have access to, so after returning the file list,
I need to filter it against an string array of allowable volumes for
that user. There is no permissions table in the db I can chack against,
and I can’t add tables.

Can this be done in Rails? I was hoping for something in a dynamically
constructed :conditions clause.
Otherwise, I would have to do array manipulation in Ruby with
potentially large arrays.


Yes, of course it works. No mention of other types of SQL constructions
in the Agile book, but a little digging online found examples.

:conditions => [path LIKE :path, {:path => “some_path_fragment%”}]