fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
152 stars 96 forks source link

Model_Orm::is_new() #362

Closed vmhnrj closed 10 years ago

vmhnrj commented 10 years ago

Unlike Model::crud::is_new(), there is no set method for Orm Object. Model::crud::is_new(false) -- works well, but not in Orm Object. please fix in next release.

emlynwest commented 10 years ago

I am not sure I see why this is needed. The "is new" status is handled for you internally by the ORM model.

WanWizard commented 10 years ago

It's even a bad idea for Model_Crud.

If you fetch a record, then flip the is_new flag, then save it, it crashes with a "duplicate key" exception. This is exactly what ORM wants to avoid.

If you need an ORM object with existing data in a new state (for example because you want to copy it), simply clone the object. That will not only reset the is_new state, but some other internal structures as well.

vmhnrj commented 10 years ago

is_new() is needed when we want to decide, whether this object is from Existing DB record, or a newly created object. This is may not be required for all scenarios, but at the end of code when developer wants to take a decision, it may be required.

WanWizard commented 10 years ago

Yes, I know what it does. But the Orm model will take care of that. Either it's loaded from the DB, and then it is not new, or it's loaded by code, and then it is new. And there isn't any other option. And the way to change a DB loaded object to new, the correct way to do that is to clone it. If you're doing something else, chances are you're doing it wrong.

So you really have to come up with a valid use-case of us to consider changing it.