Uh yeah, Color.all(:conditions => { :name => color_from_import })

http://guides.rubyonrails.org/active_record_querying.html

2009/8/4 Stijnster <st...@skylight.be>

>
> Here's an idea,
>
> I'm making an import module for a customer and have to look up related
> models all the time to link them to the imported record;
>
> ...
> @item.color = Color.find_by_name(color_from_import)
> ...
>
> Instead of hitting the database all the time, I'm extending the array
> class with a "search" call that searches values in a preloaded list
> "ActiveRecord find" style;
>
> @colors = Color.all
> ...
> @item.color = @colors.search(:first, :conditions => { :name =>
> color_from_import })
>
> or
>
> @item.color = @colors.search(12)
> @item.color = @colors.search(:all, :conditions => { :name => /test/})
>
> Can someone tell me if behaviour like this is already implementent (in
> core or using a plugin)? Here is my (premature) plugin code;
>
> http://pastie.org/570795
>
>
> Stijn
> >
>


-- 
Ryan Bigg

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to