def self.select_all_ids
self.find(:all, :select => “id”).map {|ressource| ressource.id}
end
end
I’ve created a new ressource. Now, I’d like to create a blocking that
belongs to this ressource. But validation fails because the result of
the method select_add_ids doesn’t include the id of the new ressource.
The method seems to be cached.
What kind of caching is this, and how can I prevent the method from
being cached?
(I use mysql 5.0)
the method select_add_ids doesn’t include the id of the new ressource.
The method seems to be cached.
What kind of caching is this, and how can I prevent the method from
being cached?
This is not really caching as such, just that i suspect you haven’t
fully understood what code is executed when.
In particular, the validates_inclusion_of… statement is executed
when blocking.rb is loaded (and in production this will happen exactly
onece) and so the select_all_ids is executed at that time (not when a
record is checked).
You could keep this approach using a validates method, but really this
is the sort of thing that I’d let the database enforce (via a foreign
key).
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.