I am trying to select an item from a cached array, but it does not work. I do the following:
> t=Task.last
=> #<Task id: 26, title: "Soloff" created_at: "2017-12-11 13:48:17", updated_at: "2017-12-11 15:57:12">
> t.cached_reminds
=> [#<TaskRemind id: 3, deleted_state: false, task_id: 26, user_id: 1, date: "2017-12-27 23:00:00", created_at: "2017-12-11 16:28:34", updated_at: "2017-12-11 16:28:34">, #<TaskRemind id: 2, deleted_state: false, task_id: 26, user_id: 1, date: "2017-12-28 23:00:00", created_at: "2017-12-11 16:27:16", updated_at: "2017-12-11 16:27:16">]
So my query displays a nice array, but after that, when I try to run:
t.cached_reminds.where(user_id: 1)
An action that is not recognized
Can you help me?
EDIT:
Create my model Task:
def cached_reminds
Rails.cache.fetch([self, "task_reminds"]) {task_reminds.to_a}
end
Oddly enough, when I try to run:
t.task_reminds.where(user_id: 1)
It works!!
source
share