On May 31, 2006, at 12:28, Daniel wrote:

> Hi,
>
> I have three Models
>
> User, Group and File.
>
> User habtm group
> Group habtm File
>
> How can I find all that files that a particular user has access to?
> eg user.groups.files ?

The Rails-specific list (http://lists.rubyonrails.org/mailman/ 
listinfo/rails) and wiki and things may give you a better answer  
(particularly in terms of things like query optimisation) than you'll  
get here, but...

user.groups is an array, it's not the array which has a file  
attribute, but each individual group in it, so maybe something like  
this:

class User
   def files
     self.groups.inject([]) { |arr, group| arr + group.files }
   end
end

matt smillie.