Hi:
I'm custom devolping an application and i had an issue, when calling the method isNew() it always returns false even though is inserting a new database record.
Can you help on this one?
Best regards and thanks in advance !
IsNew
IsNew() returns TRUE only if the object does not have an ID (
['data']['id'] ) set.
I can provide more information if you can offer code snippets.
['data']['id'] ) set.
I can provide more information if you can offer code snippets.
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!
Help motivate us to continue by showing your appreciation!
Thanks for your answer.
I tried to achive was someting like this:
if ( $jf->isValid() ) {
$jf->Save(FALSE);
if ( isset($data['user_ids']) ) {
$jf->setUser( $data['user_ids'] );
}
if ( $jf->isValid() ) {
$jf->Save();
#Redirect::Page( URLBuilder::getURL( array('id' => $data['id'], 'data_saved' => TRUE), 'EditCase.php') );
break;
}
}
in the above case jf->setUser calls the parent class isNew to insert or update multiple rows in a database mapped to one id ($this->getId). Like in RecurringScheduleControl if I can remember. $this->IsNew() always return false.
Best regards
Thanks in advance.
I tried to achive was someting like this:
if ( $jf->isValid() ) {
$jf->Save(FALSE);
if ( isset($data['user_ids']) ) {
$jf->setUser( $data['user_ids'] );
}
if ( $jf->isValid() ) {
$jf->Save();
#Redirect::Page( URLBuilder::getURL( array('id' => $data['id'], 'data_saved' => TRUE), 'EditCase.php') );
break;
}
}
in the above case jf->setUser calls the parent class isNew to insert or update multiple rows in a database mapped to one id ($this->getId). Like in RecurringScheduleControl if I can remember. $this->IsNew() always return false.
Best regards
Thanks in advance.
Our man from Havana
The reason why isNew() is always returning FALSE is because you call it after Save(). As soon as Save() is called the object is stored in the database and assigned an ID at that time. Therefore the object is no longer "new". Thats basically how we define "new" in TimeTrex, the object has not been saved to the database yet.
If you look at setUser() in RecurringScheduleControl, you will see that this is actually the proper procedure. You can't assign users to a object that isn't saved in the database and subsequently has an ID to be mapped to. It also doesn't use isNew() to determine insert/update, it uses isNew() to determine if it needs to delete already existing mapped entries that are not to be assigned any more.
If you look at setUser() in RecurringScheduleControl, you will see that this is actually the proper procedure. You can't assign users to a object that isn't saved in the database and subsequently has an ID to be mapped to. It also doesn't use isNew() to determine insert/update, it uses isNew() to determine if it needs to delete already existing mapped entries that are not to be assigned any more.
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!
Help motivate us to continue by showing your appreciation!
Thanks
Hi mikeb:
That's the way how I understood worked isNew(). However the explanation about isNew cheking just to delete old mapped entries clarifies more the whole scenerio. Thanks a lot I'll give a second though to my script.
Good work,
Best regards
That's the way how I understood worked isNew(). However the explanation about isNew cheking just to delete old mapped entries clarifies more the whole scenerio. Thanks a lot I'll give a second though to my script.
Good work,
Best regards
Our man from Havana
We are always interested to hear from community members that are developing custom solutions, or add-ons to TimeTrex, do you care to elaborate on what you are working on by chance?
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!
Help motivate us to continue by showing your appreciation!