If the 'folder.files' element was an array of ids then there would be
no subsequent database access to determine the size() value.
Not really true; it takes a query in either case. Your method still
needs "SELECT file_ids FROM folders WHERE id = ?". That's not really
going to perform any better than "SELECT count(*) FROM files WHERE
folder_id = ?", especially not if files.folder_id is indexed.
If you're really worried about performance, just cache Folder.file_ids
so you don't have to query it every time.
Or you could use a nested-set tree model (there are several Rails
plugins that make this easy). But storing the child keys in the parent
DB record is just asking for trouble.