On Dec 2, 12:24 pm, David Lee <[email protected]> wrote:
> Identity map does not unmap destroyed objects. Sequel should unmap the
> destroyed objects like this:
>
> x = SomeModel[1]
> x.nil? #=> false
> x.destroy
> y = SomeModel[1]
> y.nil? #=> true
>
> Instead, it current does this:
>
> x = SomeModel[1]
> x.nil? #=> false
> x.destroy
> y = SomeModel[1]
> y.nil? #=> false
> y == x #=> true
This is a bug, definitely. Do you feel comfortable working on a patch
(overriding Model#delete and removing the object from the cache after
calling super)? If not, I'll get to it hopefully by this weekend.
> Also, it would be nice if there was a way to skip the identity map on
> certain fetches, like SomeModel.direct(id).
Since the identify map is thread based, you can probably do:
model = nil
Thread.new{model = SomeModel[id]}.join
Alternatively, SomeModel.direct could be defined as:
def SomeModel.direct(id)
new(naked.first(:id=>id), true)
end
The identity map hooks into Model.load, so as long as you avoid that,
you should be fine. I don't think this is something that should be
included in the plugin.
> On a side note, Sequel::Model should have #deleted? and #destroyed?
> methods so that we can check if an object has been deleted or
> destroyed.
destroyed? is already part of the active_model plugin, FWIW.
Both methods are easy to implement, so it's mostly a question of
whether it's worth supporting them by default. Does anyone else think
they should be added?
My personal opinion is the methods are a bad idea. You generally
don't care if an object has been destroyed/deleted, you care whether
it still exists in the database (which Model#exists? is for). In
certain cases, maybe you'd rather a quick check to see if the object
was destroyed/deleted by the ruby code versus a database query to
check for sure, but that's a performance optimization, and not
something that should be encouraged for general use.
I definitely think it is a bad idea to have both. I can't imagine a
situation where you care if the object was destroyed via destroy as
opposed to deleted via delete.
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.