Re: can this be done without using find_by_sql

DarkTatka
Sat, 14 Feb 2009 23:21:21 -0000

named scope is definitely the way to go. check out
http://guides.rubyonrails.org/active_record_querying.html#_named_scopes
for more options (especialy named scope with argument)

On 14 Ún, 13:32, tonypm
<tonypmar...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
wrote:
> Just to finish the story.
>
> Sorry -  the distinct in the select is needed, I missed it out.
>
> Going a step further, I now have:
>
> named_scope :flagged_repairs, :select => ''distinct
repairs.*'', :joins
> => :repair_notes, :conditions => ["notes.flagged = ?",
true]
>
> So in my search, where I am building a dynamic scope (thanks to
> railscasts)
> I can do:
>
> scope.flagged_repairs.paginate(:page=>page, :per_page=>per_page)
>
> And it all appears to work!!
>
> Incredibly neat
>
> Tonypm
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com