Sorry, I mean get the list of user id ... cuz my query depends on user.id .. so i want to have a list which is array to go through the album..
On Mon, Jun 13, 2011 at 1:53 PM, Michael Pavling <[email protected]> wrote: > On 13 June 2011 18:33, Yennie <[email protected]> wrote: > > @id = User.find(:all, :select => 'users.id') > > @id.each do |i| > > @pic = ActiveRecord::Base.connection.select_value( > > select picture > > from albums a > > inner join Users u > > on u.id = a.id > > where u.id = i ) > > end > > end > > > > please give me some advices... > > Assuming your users have a "has_many :pictures" relationship: > > @pictures = User.all.map(&:pictures).flatten > > Or if your Users have many Albums, and Albums have many Pictures: > > @pictures = User.all.map(&:albums).flatten.map(&:pictures).flatten > > (can probably use .inject to make that smaller, but you can look that > up in the api docs) > > then you can iterate @pictures however you want in your views. > > but.... hang on... > > Aren't you just getting a list of all the Pictures? Why not use > "Picture.all"? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

