Hi,
I have a question that how to take a list of user on user table
def show_pic
 @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...
THanls you so much
-- 
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 13 June 2011 18:33, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @id = User.find(:all, :select => ''users.id'') > -ihz4oeTjUUA@public.gmane.org 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 13 June 2011 18:33, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.