Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loaded() state seems to be wrong #48

Open
furgo opened this issue Nov 11, 2009 · 3 comments
Open

loaded() state seems to be wrong #48

furgo opened this issue Nov 11, 2009 · 3 comments

Comments

@furgo
Copy link

furgo commented Nov 11, 2009

TestCase One:

$sprig->id = 1; 
$sprig->load(); 
$sprig->delete(); 

// id =1 is correctly deleted 
$sprig->id = 1; 
$sprig->load(); 

// loaded returns TRUE 
$this->assert_equal($sprig->loaded(), FALSE); 

TestCase 2:

$sprig->id = 1;
$sprig->load();
$this->assert_equal($sprig->loaded(), TRUE);

// id 10 does not exist => test returns TRUE
$sprig->id = 10;
$sprig->load();
$this->assert_equal($sprig->loaded(), FALSE);
@tector
Copy link

tector commented Feb 17, 2010

Its really time to fix this! I think it is critical bug!
issue #61 seems to be related to this one

@HNygard
Copy link

HNygard commented Feb 17, 2010

Are you making the variable $sprig to a new object in between these loads?

My guess:
If you are not, it might not be incorrect behavior by Sprig. Since the object is already loaded from database, loaded() is returning true (_loaded is set to true). If you are calling load() again, the _loaded variable is not changed (maybe it should be set to false) and is therefore still true.

@fabricasapiens
Copy link

Long time since last post, but still:
I would suggest setting ->_loaded to false when a ->delete() is done. This might be a bit against the true meaning of 'loaded', since the element was loaded succesfully, but I think what one really wants to know when one calls ->loaded() is whether the element exists or not.

Another option would be to add an extra option ->exists() that returns to false when ->delete() is executed, and has the same value as ->loaded() at all other times.

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

No branches or pull requests

3 participants