Jeroen van Ingen
2012-Mar-13 14:10 UTC
[Arel]Building query, but can''t get a proper output
I have the following code: advertisements_arel = Advertisement.order("advertisements.id DESC").arel @advertisements = (params[:website_id].present? ? advertisements_arel.where(:website_id => params[:website_id]) : advertisements_arel).to_a It returns a struct Arel::SelectManager::Row data But I''d like it to return an array of Advertisement objects (like it would normally do) so I can iterate over it more easily. Anyone know how to do that? -- Posted via http://www.ruby-forum.com/. -- 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.
Juan Pablo Avello
2012-Mar-13 14:38 UTC
Re: [Arel]Building query, but can''t get a proper output
El martes 13 de marzo de 2012 15:10:40 UTC+1, Ruby-Forum.com User escribió:> > I have the following code: > > advertisements_arel = Advertisement.order("advertisements.id > DESC").arel > @advertisements = (params[:website_id].present? ? > advertisements_arel.where(:website_id => params[:website_id]) : > advertisements_arel).to_a > > It returns a struct Arel::SelectManager::Row data > But I''d like it to return an array of Advertisement objects (like it > would normally do) so I can iterate over it more easily. Anyone know how > to do that? > > -- > Posted via http://www.ruby-forum.com/. >If you remove the .arel you get an ActiveRecord::Relation which you can iterate as if it were an Array, plus you can keep appending .where(...) as in your code Regards. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/n_jtos3VlWIJ. 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.
Jeroen van Ingen
2012-Mar-13 14:48 UTC
Re: [Arel]Building query, but can''t get a proper output
Right... stupid me... Thanks anyway ;) -- Posted via http://www.ruby-forum.com/. -- 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.
Apparently Analagous Threads
- Issue with Arel::SelectManager and insert Method
- Rails 3.1 : Complex database query with Arel 2
- Can Arel handle UPPER and LIKE condition?
- A "strict Arel" mode for ActiveRecord to prevent SQL injection vulnerabilities
- How to copy model with arel_table instance