⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

issue with callback_insert



Amit Shah
  • profile picture
  • Member

Posted 05 September 2013 - 12:52 PM

Hi Team,

 

i found a bug with callback_insert. What happens here ... as per example in the documentation, if we follow, it is as expected - we are supposed to return the last insert id ... this is useful for us to edit the same record if required. But what i noticed in here was - when we do the same, the id is not taken / updated in for the row / record. This is causing it to mark the edit url to edit/1 ... and not the returned row id..

Below is the actual scenario and a proposed solution over the same.

//Actual scenario
$callback_return = call_user_func($this->callback_insert, $post_data);

if($callback_return === false)
{
	return false;
}


//Proposed scenario

$callback_return = call_user_func($this->callback_insert, $post_data);

if($callback_return === false)
{
	return false;
} else {
	$insert_primary_key = $callback_return;
}

There was 1 more issue noticed .. when we set callback_insert(array($this), 'function_name') - this is accepted by the GC library... and it tries to make a call to a function that is not set..

I was thinking of a updating the code to check and give the error prior to execution .. like user has to set the callback function

i know this is a feasible type.. where user can just set the single string of the function name that can reside in other helper file . but we can enhance the code to check ...

if the 1st value set is instance of class or an object, we should strictly require the second element of the array to be present.

 

This way, we can ensure that the library is much much stronger then.

 

THANK YOU FOR SUCH A WONDERFUL LIBRARY

 


davidoster
  • profile picture
  • Member

Posted 05 September 2013 - 18:03 PM

Hmmm! Let me think about it!


web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 06 September 2013 - 09:44 AM

Hello [member='Amit Shah'],

 

I think you are right. For now there is not such flexibility to return the primary key for callback_insert. Can you please fork the project and have a pull request so I can actually test your code as well? It would be really helpful for everyone.

 

Thanks

Johnny


davidoster
  • profile picture
  • Member

Posted 06 September 2013 - 10:05 AM

What about the callback_after_insert? Should we take this also into consideration?

 

Also in a more general point of view, check callback_[after]_update what technique is used there? ;)