Call to undefined method setRelation1to1Fields() Error in EditFormState

Hello GroceryCRUD Enterprise community,

I’m experiencing an issue with my GroceryCRUD Enterprise implementation (version 3.1.16) in a CodeIgniter 4 project. When trying to access the edit form, I’m getting the following error:

Call to undefined method GroceryCrud\Core\State\EditFormState::setRelation1to1Fields()

Error details

The error occurs in /var/www/html/certificacion_daf/vendor/grocery-crud/enterprise/src/GroceryCrud/Core/State/EditFormState.php on line 79, where it’s trying to call the setRelation1to1Fields() method:

php

$outputData = $this->setRelation1to1Fields($outputData);

Problem analysis

The interesting thing is that the setRelation1to1Fields() method is actually defined in the parent class StateAbstract, but for some reason, it’s not being recognized when called from EditFormState.

I’ve examined both classes, and EditFormState extends StateAbstract correctly:

php

class EditFormState extends StateAbstract {

The setRelation1to1Fields() method is defined in StateAbstract.php (I’ve verified this), but when the code execution reaches the call in EditFormState, PHP throws the undefined method error.

My environment

  • CodeIgniter 4
  • PHP 8.1
  • GroceryCRUD Enterprise 3.1.16
  • I recently upgraded from version 3.1.4 to 3.1.16

My implementation

Here’s my simple controller method:

php

public function personaDaf()
{
    $crud = $this->templater->_getGroceryCrudEnterprise();
    $crud->setCsrfTokenName(csrf_token());
    $crud->setCsrfTokenValue(csrf_hash());
    $crud->setTable('persona_daf');
    $output = $crud->render();
    return $this->templater->_grocerycrud_output($output);
}

Attempted solutions

  • Tried updating via Composer: composer update grocery-crud/enterprise --with-dependencies
  • Tried requiring the specific version: composer require "grocery-crud/enterprise:^3.1.16" --prefer-dist
  • Cleared Composer cache and updated again

None of these solutions resolved the issue. I’m avoiding modifying vendor files directly since that’s not a sustainable solution.

Has anyone experienced a similar issue? Any suggestions on how to resolve this without modifying the vendor files? Perhaps using the replaceState() method to override the EditFormState class?

Hello @stacknews ,

Unfortunately I can’t reproduce your issue. Can you please describe how did you set the relation 1 to 1? I can’t find anywhere at your controller method:

public function personaDaf()
{
    $crud = $this->templater->_getGroceryCrudEnterprise();
    $crud->setCsrfTokenName(csrf_token());
    $crud->setCsrfTokenValue(csrf_hash());
    $crud->setTable('persona_daf');
    $output = $crud->render();
    return $this->templater->_grocerycrud_output($output);
}

The setRelation1to1 I was looking for something like this:

$crud->setRelation1to1('address_id', 'employees_addresses', [
    'address_line_1','city','address_line_2','postal_code','country'
]);

How exactly are you implementing the relation 1 to 1?

Regards
Johnny