Find on Element without hitting the database

Hi,

I have a task model with a one to many relationship with a todo model.

If I do a find on the task model:

task = Tasks.find(1)

Is there a way to search the todos on a particular field without
hitting the database again. For example, If the todo model had a field
named label, could I do something like task.todos.find_by_label("…")
but not have it hit the database, because I already have all of the
todos within the task.

Is it best just to write a helper method that loops through the todos,
looking for the one with the correct label or is there something
already build into ruby to do this?

Thanks for your help!

On Jan 29, 2008, at 10:06 AM, lundie wrote:

named label, could I do something like task.todos.find_by_label("…")
but not have it hit the database, because I already have all of the
todos within the task.

Is it best just to write a helper method that loops through the todos,
looking for the one with the correct label or is there something
already build into ruby to do this?

Thanks for your help!

Look at the docs for “eager loading” and the use of the :include option.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Great, Ill take a look,

Thanks for your help!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs