Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Calling #reload on a resource deleted in another process should mark the resource destroyed #157

Open
d11wtq opened this issue Oct 19, 2011 · 4 comments
Milestone

Comments

@d11wtq
Copy link
Contributor

d11wtq commented Oct 19, 2011

I'll have a look at this later, but to me, it seems logical that the following behaviour should not exhibit:

In process A:

@resource = Model.get!(1)
@resource.destroy

In process B, simultaneously (or in the same process without the identity map):

@resource = Model.get!(1)

# process A deletes the resource around about here

p @resource.reload.destroyed? #=> false

To me, since we have a persisted state that indicates the resource is saved, yet we've failed to find the resource when doing a reload (note no exception is thrown), the resource should be flagged as destroyed.

This crops up in rails specs trying to assert that a record has been destroyed by a controller (in a semantic way).

@solnic
Copy link
Contributor

solnic commented Oct 30, 2011

@d11wtq I added this to 1.3.0 milestone

@d11wtq
Copy link
Contributor Author

d11wtq commented Oct 30, 2011

Awesome, thanks. I spent an entire day working on this last week but wasn't able to make it work. Or rather, I could get it working, but only if a kicker method was called before calling #destroyed?.

@solnic
Copy link
Contributor

solnic commented Oct 30, 2011

@d11wtq I don't remember exactly how #reload works. I think all it does is reseting to initial state w/o actually getting back to the db.

@d11wtq
Copy link
Contributor Author

d11wtq commented Oct 30, 2011

It clears the keys and the subjects (properties), forcing lazy-loading to take place, which actually happens in the Collection, not the Resource per se. Since #reload is invoked on the Resource, I was able to force that lazy-loading to occur (in the Collection), then consult the Collection to check if self is still in it. If self (the Resource in question) has mysteriously disappeared from the Collection, then I set the persistence state (to what, I forget... I think Immutable, which plays a role in whether or not #destroyed? returns true). The issue I was running into, and not entirely sure why, was that calling #reload on a clean resource wasn't having any impact, but calling it on a dirty resource was doing exactly what I wanted, marking the resource as destroyed, after observing itself disappear from the Collection. I eventually gave in and accepted defeat ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants