⚠ 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

Callback_after_insert primary_key issue



jesinor
  • profile picture
  • Member

Posted 12 April 2013 - 18:06 PM

Hello;

 

When I'm trying to use the primary_key of a non integer field in an after_insert callback the value returned is 0.

This also affects the updates in a n-n-relationship (giving errors most of the time).

 

Is there any way to overcome this problem? (if possible I wouldn't like to create an autoincrement pk)

Where should I insert my code to modify this pk value so that it would work in a n-n-relationship?

 

I noted that the model gets the pk value from db->insert_id() and that seems to be the problem for this example.

 

Thank you

 

Norberto

 


jesinor
  • profile picture
  • Member

Posted 12 April 2013 - 18:49 PM

Meanwhile I modified the library ( although this is not my preferred way concerning future updates )

 

Starting in line 917 of grocery_crud library
using get_primary_key() instead of insert_id when value is 0.

if($insert_result !== false)
{
               // new line
               if ($insert_result == 0)
                     $insert_primary_key = $insert_data[$this->get_primary_key()];
               else
                // end modifications                    
                   $insert_primary_key = $insert_result;   // original line
....

Well, this seems to work for this problem at least... but is a temporary solution (no error check if no pk defined etc. )