nova-toggle icon indicating copy to clipboard operation
nova-toggle copied to clipboard

update pivot field via editableIndex tries to update related model in stead of pivot model

Open AforDesign opened this issue 2 years ago • 0 comments

Thanks for creating this great and very helpful package.

It works without problems in most cases, but I did encounter a bug in the following situation (models are set correctly):

  • Model-A has a BelongsToMany Field, attaching it to Model-B
  • The pivot tabel of Model-A_Model-B has an additional field, for example 'is_active'
  • This pivot field is included in the BelongsToMany relation, with the '->editableIndex()' method
  • On the index page of Model A, the toggle shows the correct value Thus it's value is correctly interpreted by the Toggle field (wonderful!)
  • When you click on the toggle An error occurs: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'is_active' in 'field list' ( SQL: update Model-B set is_default = 0, Model-B.updated_at = [date] where id =[id of model-B)
  • The update function, tries to updated the field in the table of the related model insted of the pivot table

So, in short: The field is shown correctly on the index view, but updating it targets the wrong table (/model)

AforDesign avatar Jan 17 '22 15:01 AforDesign