Forum: Ruby on Rails Add'l filtering on HABTM

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
21c26386eabccd11f40c029b0ebf94e7?d=identicon&s=25 Brian Ablaza (zakifataya)
on 2006-04-10 21:08
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.
21c26386eabccd11f40c029b0ebf94e7?d=identicon&s=25 Brian Ablaza (zakifataya)
on 2006-04-11 17:56
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%"}]
This topic is locked and can not be replied to.