create_table :users do |t|
t.column :name, :string
t.column :rich, :boolean
t.column :book_id, :integer
end
create_table :books do |t|
t.column :name, :string
end
If I have around half-million ‘rich’ User’s that read a very small
amount of books, what is the best way I can query the database for the
list of the names of these books?
I can perform User.find(:all, :conditions => [‘rich is true’], :include
[:books]), but I believe this will return a very large number of users,
and then I’d have to loop through each one to get the book names.
If you just need the names of books for rich users … then you need
to add user_id column to books table,
then give your regular query for books table directly.